PDA

View Full Version : I was wrong about dofile. (maybe)



Ian
02-13-2007, 10:54 PM
Does RunScript (as the name implies) just run the given source file regardless of whether it has already been executed? dofile does just that. The package table (which is now disabled in Novashell) is preferable because it only executes a script once. I made a replacement of require that relies on RunScript:



do
local scripts = {}

function require(filename)
if not scripts[filename] then
scripts[filename] = true
RunScript(filename)
end
end
end

Seth
02-14-2007, 12:24 AM
Yes, you're right, RunScript will load multiple times. I'll add this function to system/misc_utils.lua.

Note: Probably shouldn't use it from any entity namespace, as it will mark it as loaded but it will actually be destroyed when the entity is... but really, global type scripts shouldn't be loaded from entity scripts anyway.