lewisclark / glua-steal

Retrieves client-sided Lua files from Garry's Mod game servers
GNU General Public License v3.0
151 stars 15 forks source link

Feature, pre autorun file. #45

Closed wrefgtzweve closed 1 year ago

wrefgtzweve commented 1 year ago

A file that runs once before any server lua might be very useful, currently it'd be possible with lua but having an option to just automatically do it would be useful. Something like pre-autorun.lua or so. I ran into this issue when i was trying to test some pre autorun code but it seemed like it still constantly ran.

if firstRun then return end
firstRun = true

Simply running this at the top of the file didn't seem to work as maybe the environment constantly changes per file? I'm not exactly sure but it'd just be neat to have a file to run only once.

lewisclark commented 1 year ago

Sure, it seems like a useful addition.

The environment is created from scratch for each invocation to gluasteal.lua. You would have to store the variable in _G.

if _G.firstRun then return end
_G.firstRun = true

I prefer to check if the file being executed is includes/init.lua which is the first file to execute in the Lua state.

if gluasteal.SCRIPT ~= "includes/init.lua" then return end

-- Code that runs once, before includes/init.lua
lewisclark commented 1 year ago

On second thought, I'm not sure it's worthwhile implementing this when all you need is:

if gluasteal.SCRIPT == "includes/init.lua" then
    gluasteal.include("pre-autorun.lua")
end
wrefgtzweve commented 1 year ago

Yeah that'd pretty much run before any lua, might not be worth the time to make that a build in feature.