public void Init() { lua_ = LuaAPI.NewState(); lua_.L_OpenLibs(); lua_.L_RequireF(GameScript.LIB_NAME, GameScript.OpenLib, false); lua_.L_RequireF(Sys.LIB_NAME, Sys.OpenLib, true); lua_.L_RequireF(Global_.LIB_NAME, Global_.OpenLib, true); #region registGlobal GameScript.RegistGlobalEnum(typeof(ScriptGameEvent)); GameScript.RegistGlobalEnum(typeof(GuidePointerRotateType)); GameScript.RegistGlobalEnum(typeof(BattlePosition)); GameScript.RegistGlobalEnum(typeof(PropertyType)); GameScript.RegistGlobalEnum(typeof(OrderParamType)); GameScript.RegistGlobalEnum(typeof(GroupType)); GameScript.RegistGlobalEnum(typeof(StateType)); GameScript.RegistGlobalEnum(typeof(ItemMainType)); GameScript.RegistGlobalEnum(typeof(ItemSubType)); GameScript.RegistGlobalEnum(typeof(TogetherStateType)); GameScript.RegistGlobalEnum(typeof(StateType)); GameScript.RegistGlobalEnum(typeof(GuideAimType)); GameScript.RegistGlobalEnum(typeof(WeaponType)); GameScript.RegistGlobalEnum(typeof(JobType)); GameScript.RegistGlobalEnum(typeof(Constant)); GameScript.RegistGlobalEnum(typeof(BattleJudgeType)); GameScript.RegistGlobalEnum(typeof(SenseActorType)); #endregion LoadScript(luaEntryFile_); }
public void InitLuaMgr( ) { m_luaState = LuaAPI.NewState(); m_luaState.L_OpenLibs(); ToolLib.LuaOpenCommonLib(m_luaState); }
void Awake() { if (_lua == null) { _lua = LuaAPI.NewState(); // создаем _lua.L_OpenLibs(); _lua.L_RequireF("mylib", OpenLib, true); _status = _lua.L_DoFile(LuaScriptFile); // throw new Exception( _lua.ToString(-1) ); if (_status != ThreadStatus.LUA_OK) { Debug.LogError("Error parsing lua code"); } if (!_lua.IsTable(-1)) { throw new Exception("framework main's return value is not a table"); } // _lua.L_LoadFile (LuaScriptFile); mainRef = StoreMethod("main"); // _lua.Resume (null, 0); // _lua.Pop (1); } }
void Awake() { Debug.Log("LuaScriptController Awake"); if (mLuaState == null) { mLuaState = LuaAPI.NewState(); mLuaState.L_OpenLibs(); var status = mLuaState.L_DoFile(LUA脚本入口); if (status != ThreadStatus.LUA_OK) { throw new Exception(mLuaState.ToString(-1)); } if (!mLuaState.IsTable(-1)) { throw new Exception("entry main's return value is not a table"); } mAwakeRef = StoreMethod("awake"); mStartRef = StoreMethod("start"); mUpdateRef = StoreMethod("update"); mLateUpdateRef = StoreMethod("late_update"); mFixedUpdateRef = StoreMethod("fixed_update"); mLuaState.Pop(1); Debug.Log("Lua Init Done"); } CallMethod(mAwakeRef); }
void Awake() { Debug.Log("LuaScriptController Awake"); if (Lua == null) { Lua = LuaAPI.NewState(); Lua.L_OpenLibs(); var status = Lua.L_DoFile(LuaScriptFile); if (status != ThreadStatus.LUA_OK) { throw new Exception(Lua.ToString(-1)); } if (!Lua.IsTable(-1)) { throw new Exception( "framework main's return value is not a table"); } AwakeRef = StoreMethod("awake"); StartRef = StoreMethod("start"); UpdateRef = StoreMethod("update"); LateUpdateRef = StoreMethod("late_update"); FixedUpdateRef = StoreMethod("fixed_update"); Lua.Pop(1); Debug.Log("Lua Init Done"); } CallMethod(AwakeRef); }
LuaInstance() { lua_ = LuaAPI.NewState(IntPtr.Zero); lua_.L_OpenLibs(); LuaClassList.Init(); for (int i = 0; i < 10; i++) { params_[i] = new object[i]; } //Register Debug.Log Type debugClassType = typeof(Debug); LuaClass lua_class = RegisterLuaClass(debugClassType); FuncInfo[] funcInfos; if (LuaClassList.classes.TryGetValue(debugClassType, out funcInfos)) { for (int j = 0; j < funcInfos.Length; j++) { lua_class.RegisterStaticFunction(funcInfos[j]); } } lua_class.EndRegisterClass(); }
protected void Awake() { if (mLuaState == null) { mLuaState = LuaAPI.NewState(); mLuaState.L_OpenLibs(); if (null != LUAEntryFileName && LUAEntryFileName.Length > 0) { var status = mLuaState.L_DoFile(LUAEntryFileName); if (status != ThreadStatus.LUA_OK) { throw new Exception(mLuaState.ToString(-1)); } if (!mLuaState.IsTable(-1)) { throw new Exception("entry main's return value is not a table"); } string[] funcList = MethodNameList(); if (null != funcList) { for (int i = 0; i < funcList.Length; ++i) { var s = funcList[i]; if (mLuaFunctionRefs.ContainsKey(s)) { mLuaFunctionRefs.Remove(s); } int funcRef = StoreMethod(s); mLuaFunctionRefs.Add(s, funcRef); } } mLuaState.Pop(1); } } }
private LuaMgr() { Env = LuaAPI.NewState(); Env.L_OpenLibs(); Env.L_RequireF(LuaTriggerLib.LIB_NAME, LuaTriggerLib.OpenLib, false); Env.L_RequireF(LuaControllerLib.LIB_NAME, LuaControllerLib.OpenLib, false); Env.L_RequireF(LuaDebugLib.LIB_NAME, LuaDebugLib.OpenLib, false); }
void Start() { Lua = LuaAPI.NewState(); Lua.L_OpenLibs(); var status = Lua.L_DoString(luastr); Debug.Log(status); }
private bool LUA_Init() { _lua = LuaAPI.NewState(); _lua.L_OpenLibs(); _lua.L_RequireF("io", this.GetComponent <ProcLibs>().OpenIOLib, true); _lua.L_RequireF("graph", this.GetComponent <ProcLibs>().OpenGraphicsLib, true); _thread = _lua.NewThread(); return(true); }
public void PrepareLuaState() { lua_ = LuaAPI.NewState(IntPtr.Zero); lua_.L_OpenLibs(); #if UNITY_EDITOR || LuaDebugger LuaAPI.luaopen_RMDB(lua_.GetLuaPtr(), 0); #endif //Register Global Class LuaDebug.RegisterToLua(lua_, typeof(LuaDebug)); RegisterType(typeof(Register)); LuaDBTable.RegisterToLua(lua_, typeof(LuaDBTable)); }
public void InitializationFile(string luaScriptFile, uint storeMethodMask, OnStoreMethod storeMethod) { if (Lua != null) { return; } // 创建 Lua 虚拟机 Lua = LuaAPI.NewState(); // 加载基本库 Lua.L_OpenLibs(); // 加载 Lua 脚本文件 ThreadStatus status = Lua.L_DoFile(luaScriptFile); // 捕获错误 if (status != ThreadStatus.LUA_OK) { throw new Exception(Lua.ToString(-1)); } // 确保 framework/main.lua 执行结果是一个 Lua Table if (!Lua.IsTable(-1)) { throw new Exception("framework main's return value is not a table"); } // 从 framework/main.lua 返回的 table 中读取 awake 字段指向的函数 // 并保存到 AwakeRef 中 (可以将 AwakeRef 视为这个函数的句柄) if ((storeMethodMask & LuaScriptDefine.StoreMethodMask_Awake) == LuaScriptDefine.StoreMethodMask_Awake) { AwakeRef = StoreMethod("awake"); } if ((storeMethodMask & LuaScriptDefine.StoreMethodMask_Start) == LuaScriptDefine.StoreMethodMask_Start) { StartRef = StoreMethod("start"); } if ((storeMethodMask & LuaScriptDefine.StoreMethodMask_Update) == LuaScriptDefine.StoreMethodMask_Update) { UpdateRef = StoreMethod("update"); } if ((storeMethodMask & LuaScriptDefine.StoreMethodMask_LateUpdate) == LuaScriptDefine.StoreMethodMask_LateUpdate) { LateUpdateRef = StoreMethod("late_update"); } if ((storeMethodMask & LuaScriptDefine.StoreMethodMask_FixedUpdate) == LuaScriptDefine.StoreMethodMask_FixedUpdate) { FixedUpdateRef = StoreMethod("fixed_update"); } if (storeMethod != null) { storeMethod(); } // 不再需要 framework/main.lua 返回的 table 了,将其从栈上弹出 Lua.Pop(1); }
void create_state() { if (_luaState == null) { LuaFile.SetPathHook(path_hook); _luaState = LuaAPI.NewState(); _luaState.L_OpenLibs(); _luaState.L_DoString(_waitFunc); register_default_functions(); register_common_libs(); register_libs(); } }
void initialLua() { // 创建 Lua 虚拟机 mlua = LuaAPI.NewState(); // 加载基本库 mlua.L_OpenLibs(); mlua.L_RequireF(LuaTest.LIB_NAME // 库的名字 , LuaTest.OpenLib // 库的初始化函数 , false // 不默认放到全局命名空间 (在需要的地方用require获取) ); ConsoleEx.DebugLog("Lua Init Done", ConsoleEx.YELLOW); loadLuaFile(); }
protected void InitLuaLib() { if (mLuaState == null) { mLuaState = LuaAPI.NewState(); mLuaState.L_OpenLibs(); LuaEncLib.OpenLib(mLuaState); } string entryFileName = LUAEntryFileName; if (null != entryFileName && entryFileName.Length > 0) { var status = mLuaState.L_DoFile(entryFileName); if (status != ThreadStatus.LUA_OK) { throw new Exception(mLuaState.ToString(-1)); } if (!mLuaState.IsTable(-1)) { throw new Exception("entry main's return value is not a table"); } OnEntryFileOvered(mLuaState.ToObject(-1) as LuaTable); string[] funcList = MethodNameList(); if (null != funcList) { for (int i = 0; i < funcList.Length; ++i) { var s = funcList[i]; if (mLuaFunctionRefs.ContainsKey(s)) { #if !UNITY_3 && !UNITY_4 && !UNITY_5 FileLogMgr.OutToFileW("注册方法[{0}时发现同名的方法,删掉老的注册新的!", s); #else Debug.LogWarning("注册方法" + s + "时发现同名的方法,删掉老的注册新的!"); #endif //UnStoreMethod(s, mLuaFunctionRefs[s]); mLuaFunctionRefs.Remove(s); } int funcRef = StoreMethod(s); mLuaFunctionRefs.Add(s, funcRef); } } mLuaState.Pop(1); } }
public static LuaProto CompileFile(string filename) { // var lua = LuaAPI.NewState(); // var reader = new BinaryReader( File.Open(filename, FileMode.Open) ); // var p = new Parser( lua ); // return p.Parse( reader, "@" + filename ); var lua = LuaAPI.NewState(); var status = lua.L_LoadFileX(filename, null); if (status != ThreadStatus.LUA_OK) { Fatal(lua.ToString(-1)); } var cl = ((LuaState)lua).Top.V.ClLValue(); return(cl.Proto); }
public void Init() { _luaState = LuaAPI.NewState(); _luaState.L_OpenLibs(); _luaState.L_RequireF("LuaLib", LuaLib.Init, false); LuaLib.InitGlobal(_luaState); LuaLib.RegisterLightUserDataLuaInterface(); _luaState.Pop(_luaState.GetTop()); // 添加错误log函数 _luaState.PushCSharpFunction(Traceback); _traceBackIndex = _luaState.GetTop(); // 加载Constants.lua var status = _luaState.L_DoFile("Constants.lua"); if (status != ThreadStatus.LUA_OK) { throw new Exception(_luaState.ToString(-1)); } InitGlobalFields(); }
private bool Load() { string LuaFile = "config.lua"; Lua = LuaAPI.NewState(); Lua.L_OpenLibs(); ThreadStatus status = Lua.L_DoFile(LuaFile); if (status != ThreadStatus.LUA_OK) { Debug.LogError("Load Lua File Error!"); return(false); } if (!Lua.IsTable(-1)) { Debug.LogError("Load Lua File Error!"); return(false); } this.CacheToGlobalConfig(); return(true); }
public LuaHolder() { mLuaState = LuaAPI.NewState(); mLuaState.L_OpenLibs(); }
public static ILuaState luaL_newstate() { return(LuaAPI.NewState()); }
private LuaMgr() { m_luaState = LuaAPI.NewState(); m_luaState.L_OpenLibs(); }