//所有模块的包先被加载 //所有Lua中的文件夹定义为一个包 private void UF_LoadLuaModulesPackages(List <AssetDataBases.AssetFileInfo> list) { if (m_Luastate == null || list == null) { return; } HashSet <string> hashmap = new HashSet <string>(); //遍历全部的资源信息文件,获取其相对路径 foreach (var v in list) { string dirName = GHelper.UF_GetDirectoryName(v.absName); if (!hashmap.Contains(dirName)) { hashmap.Add(dirName); } } int top = m_Luastate.LuaGetTop(); try { //设置module 记录包路径模块 m_Luastate.LuaCreateTable(); m_Luastate.LuaPushValue(-1); m_Luastate.LuaSetGlobal(MODULE_NAME); //按层级创建talbe pacakge foreach (var v_path in hashmap) { int s_top = m_Luastate.LuaGetTop(); foreach (var p_name in GHelper.UF_SplitString(v_path, '/')) { if (string.IsNullOrEmpty(p_name)) { continue; } if (p_name == "Runtimes") { //Runtimes作为全局根结点 m_Luastate.LuaGetGlobal("_G"); continue; } m_Luastate.LuaGetField(-1, p_name); if (m_Luastate.LuaIsNil(-1)) { m_Luastate.LuaRemove(-1); m_Luastate.LuaCreateTable(); m_Luastate.LuaPushValue(-1); m_Luastate.LuaSetField(-3, p_name); } } //设置到Module中记录 m_Luastate.LuaGetGlobal(MODULE_NAME); m_Luastate.LuaPushValue(-2); m_Luastate.LuaSetField(-2, v_path); m_Luastate.LuaSetTop(s_top); } } catch (Exception e) { Debugger.UF_Exception(e); } m_Luastate.LuaSetTop(top); }