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