@@ -234,24 +234,25 @@ void LuaStateWrapper::Initialize() {
234
234
235
235
luaL_dostring (m_State,
236
236
// Add cls() as a shortcut to ConsoleMan:Clear().
237
- " cls = function() ConsoleMan:Clear(); end"
238
- " \n "
237
+ " cls = function() ConsoleMan:Clear(); end\n "
239
238
// Override "print" in the lua state to output to the console.
240
- " print = function(stringToPrint) ConsoleMan:PrintString(\" PRINT: \" .. tostring(stringToPrint)); end"
241
- " \n "
239
+ " print = function(stringToPrint) ConsoleMan:PrintString(\" PRINT: \" .. tostring(stringToPrint)); end\n "
242
240
// Override random functions to appear global instead of under LuaMan
243
241
" SelectRand = function(lower, upper) return LuaMan:SelectRand(lower, upper); end;\n "
244
242
" RangeRand = function(lower, upper) return LuaMan:RangeRand(lower, upper); end;\n "
245
243
" PosRand = function() return LuaMan:PosRand(); end;\n "
246
244
" NormalRand = function() return LuaMan:NormalRand(); end;\n "
247
245
// Override "math.random" in the lua state to use RTETools MT19937 implementation. Preserve return types of original to not break all the things.
248
- " math.random = function(lower, upper) if lower ~= nil and upper ~= nil then return LuaMan:SelectRand(lower, upper); elseif lower ~= nil then return LuaMan:SelectRand(1, lower); else return LuaMan:PosRand(); end end"
249
- " \n "
246
+ " math.random = function(lower, upper) if lower ~= nil and upper ~= nil then return LuaMan:SelectRand(lower, upper); elseif lower ~= nil then return LuaMan:SelectRand(1, lower); else return LuaMan:PosRand(); end end\n "
250
247
// Override "dofile"/"loadfile" to be able to account for Data/ or Mods/ directory.
251
- " OriginalDoFile = dofile; dofile = function(filePath) filePath = PresetMan:GetFullModulePath(filePath); if filePath ~= '' then return OriginalDoFile(filePath); end end;"
252
- " OriginalLoadFile = loadfile; loadfile = function(filePath) filePath = PresetMan:GetFullModulePath(filePath); if filePath ~= '' then return OriginalLoadFile(filePath); end end;"
248
+ " OriginalDoFile = dofile; dofile = function(filePath) filePath = PresetMan:GetFullModulePath(filePath); if filePath ~= '' then return OriginalDoFile(filePath); end end;\n "
249
+ " OriginalLoadFile = loadfile; loadfile = function(filePath) filePath = PresetMan:GetFullModulePath(filePath); if filePath ~= '' then return OriginalLoadFile(filePath); end end;\n "
250
+ // Override "require" to be able to track loaded packages so we can clear them when scripts are reloaded.
251
+ " _RequiredPackages = {};\n "
252
+ " OriginalRequire = require; require = function(filePath) _RequiredPackages[filePath] = true; return OriginalRequire(filePath); end;\n "
253
+ " _ClearRequiredPackages = function() for k, v in pairs(_RequiredPackages) do print(\" clearing: \" .. k); package.loaded[k] = nil; end; _RequiredPackages = {}; end;\n "
253
254
// Internal helper functions to add callbacks for async pathing requests
254
- " _AsyncPathCallbacks = {};"
255
+ " _AsyncPathCallbacks = {};\n "
255
256
" _AddAsyncPathCallback = function(id, callback) _AsyncPathCallbacks[id] = callback; end\n "
256
257
" _TriggerAsyncPathCallback = function(id, param) if _AsyncPathCallbacks[id] ~= nil then _AsyncPathCallbacks[id](param); _AsyncPathCallbacks[id] = nil; end end\n " );
257
258
}
@@ -415,7 +416,7 @@ void LuaMan::Destroy() {
415
416
}
416
417
417
418
void LuaStateWrapper::ClearUserModuleCache () {
418
- luaL_dostring (m_State, " for m, n in pairs(package.loaded) do if type(n) == \" boolean \" then package.loaded[m] = nil; end; end ;" );
419
+ luaL_dostring (m_State, " _ClearRequiredPackages() ;" );
419
420
}
420
421
421
422
void LuaStateWrapper::ClearLuaScriptCache () {
0 commit comments