Updater with glua?

Hey, can i somehow make script, that updates my code when the server is running? Like when i call function, it fetches the code from http/data folder and updates already running code?

You can’t edit addons/files in lua/ or addons/ using file.Write/File:Write, but you could just read a file from data/ every time the server starts up/whenever you want and use RunString/CompileString

Get the code from your website. Did it fetch the code successfully and did the code run? If yes to both of those, save it to a file. If no to either of those, attempt to load an earlier version (the last code fetched that ran successfully, the one you saved to a file).

http.Fetch

file.Write

Global.CompileString

Global.pcall

I had a script in '12 that did something similar but only fetched code on launch.

[lua]hook.Add( “InitPostEntity”, “DLTH”, function()
if GAMEMODE.Name == “MovieTheater_V3” then
http.Get( “http://www.yorwebsite.com/code.txt”, ‘’, DLupdate)

	else
print("Your not on GMod Theater! TheaterHelper Offline!")
end

end)

function DLupdate(ver,data)
RunString(ver)
end
[/lua]

If i force it to update, how would i stop the current code and run the new? Like how do i overwrite it?

With an if statement.

What?

Wouldn’t it just override the old automatically?

Probably, if its in global table the whole code. I think if i made hook for every script DestroyScripts that will delete all locals and all that stuff?

And now, how would i send ~400 lines of code in every file to client?

Net library (net.WriteData/ReadData) and util.Compress/Decompress.

Or you could http.get on the client

[editline]29th October 2015[/editline]

And then execute the code

Nah, that meams they can view the code alot easier, they can get it through net, but it is harder as you cant see the source code.
Is it possible to include("…/…/…/data/files/file.lua")?

It’s possible

http://puu.sh/l2XSH/46b4ef9f82.png

But what will happen with AddCSLuaFile? Cant test but thanks!

I wouldn’t use AddCSLuaFile tbh, use the net library with util.Compress to send the file contents to the client on a hook or something

Can you use resource.AddFile live and dynamically like that anyway?

So you’re worried they can view the code if you use http on the client, but sending the file from the server and saving it as a file in their garry’s mod directory isn’t as easy?
There is no way you can prevent the client seeing the code that runs on their client.
The only proper way to make your code secure on the client is by checking if every interaction is valid serverside, and moving sensitive code to the server. There’s no point doing some silly hack to “hide” the code clientside, because anyone with decent knowledge can go around it and view your code with ease.