Skip to content

Commit

Permalink
loadfile common lua instead of dofile
Browse files Browse the repository at this point in the history
  • Loading branch information
audinowho committed May 15, 2024
1 parent 826678e commit a1f77c2
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions RogueEssence/Lua/LuaEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,21 @@ private string GetModulePath(string scriptPath, string moduleName)
return null;
}

private void ModLoadFile(string loadPath)
{
foreach (string modPath in PathMod.FallforthPaths(SCRIPT_PATH))
{
string modulePath = GetModulePath(modPath, loadPath);
if (modulePath != null)
{
SetLoadPath(modPath);
LuaState.LoadFile(modulePath);
//RunString(String.Format("require('{0}')", loadPath));
}
}
SetLoadPath(PathMod.NoMod(SCRIPT_PATH));
}

private void ModDoFile(string loadPath)
{
foreach (string modPath in PathMod.FallforthPaths(SCRIPT_PATH))
Expand Down Expand Up @@ -659,6 +674,21 @@ private LuaTable ModLoadTable(string loadPath)
return tbl;
}

private void ModLoadService(string loadPath)
{
foreach (string modPath in PathMod.FallbackPaths(SCRIPT_PATH))
{
string modulePath = GetModulePath(modPath, loadPath);
if (modulePath != null)
{
SetLoadPath(modPath);
LuaState.DoFile(modulePath);
break;
}
}
SetLoadPath(PathMod.NoMod(SCRIPT_PATH));
}

/// <summary>
/// Expose the list of available service callbacks names to Lua. It should make it easier for script devs to get a list of them to fiddle with.
/// </summary>
Expand Down Expand Up @@ -908,7 +938,7 @@ private void CacheMainScripts()

DiagManager.Instance.LogInfo("[SE]:Caching common lib...");
//Cache common lib
ModDoFile(SCRIPT_COMMON);
ModLoadFile(SCRIPT_COMMON);
DiagManager.Instance.LogInfo("[SE]:Loading events...");
//load events
ModDoFile(SCRIPT_EVENT);
Expand Down Expand Up @@ -948,10 +978,11 @@ private void CacheMainScripts()
//LuaFunction createNew = LuaEngine.Instance.RunString("return function(tbl) return tbl:new() end").First() as LuaFunction;
foreach (string moduleName in moduleNames)
{
LuaTable servicetbl = ModLoadTable(Path.Join("services", moduleName));
//LuaTable servicetbl = ModLoadTable(Path.Join("services", moduleName));
ModLoadService(Path.Join("services", moduleName));
//object[] obj = createNew.Call(servicetbl);
//register this variable
m_scrsvc.AddService(moduleName, servicetbl);
//m_scrsvc.AddService(moduleName, servicetbl);
}
}

Expand Down Expand Up @@ -1358,8 +1389,10 @@ private void RunAssetScript(string relpath, string assetname, string importpath,
{
//LuaState.LoadFile(abspath);
//RunString(String.Format("{0} = require('{1}');", globalsymbol, importpath), abspath);
LuaTable state = ModLoadTable(relpath);
LuaState[globalsymbol] = state;
LuaState[globalsymbol] = LuaEngine.Instance.RunString("return {}").First() as LuaTable;
ModDoFile(relpath);
//LuaTable state = ModLoadTable(relpath);
//LuaState[globalsymbol] = state;
}

/// <summary>
Expand Down

0 comments on commit a1f77c2

Please sign in to comment.