public static void OpenLibs(IntPtr L) { LuaDLL.lua_getglobal(L, "tolua"); LuaDLL.lua_pushstring(L, "findtype"); LuaDLL.lua_pushcfunction(L, new LuaCSFunction(LuaReflection.FindType)); LuaDLL.lua_rawset(L, -3); LuaDLL.lua_pushstring(L, "loadassembly"); LuaDLL.tolua_pushcfunction(L, new LuaCSFunction(LuaReflection.LoadAssembly)); LuaDLL.lua_rawset(L, -3); LuaDLL.lua_pushstring(L, "getmethod"); LuaDLL.tolua_pushcfunction(L, new LuaCSFunction(LuaReflection.GetMethod)); LuaDLL.lua_rawset(L, -3); LuaDLL.lua_pushstring(L, "getconstructor"); LuaDLL.tolua_pushcfunction(L, new LuaCSFunction(LuaReflection.GetConstructor)); LuaDLL.lua_rawset(L, -3); LuaDLL.lua_pushstring(L, "gettypemethod"); LuaDLL.tolua_pushcfunction(L, new LuaCSFunction(LuaReflection.GetTypeMethod)); LuaDLL.lua_rawset(L, -3); LuaDLL.lua_pushstring(L, "getfield"); LuaDLL.tolua_pushcfunction(L, new LuaCSFunction(LuaReflection.GetField)); LuaDLL.lua_rawset(L, -3); LuaDLL.lua_pushstring(L, "getproperty"); LuaDLL.tolua_pushcfunction(L, new LuaCSFunction(LuaReflection.GetProperty)); LuaDLL.lua_rawset(L, -3); LuaDLL.lua_pushstring(L, "createinstance"); LuaDLL.tolua_pushcfunction(L, new LuaCSFunction(LuaReflection.CreateInstance)); LuaDLL.lua_rawset(L, -3); LuaDLL.lua_pop(L, 1); LuaState luaState = LuaState.Get(L); luaState.BeginPreLoad(); luaState.AddPreLoad("tolua.reflection", new LuaCSFunction(LuaReflection.OpenReflectionLibs)); luaState.EndPreLoad(); }
public static void OpenLibs(IntPtr L) { LuaDLL.lua_getglobal(L, "tolua"); LuaDLL.lua_pushstring(L, "isnull"); LuaDLL.lua_pushcfunction(L, IsNull); LuaDLL.lua_rawset(L, -3); LuaDLL.lua_pushstring(L, "tolstring"); LuaDLL.tolua_pushcfunction(L, BufferToString); LuaDLL.lua_rawset(L, -3); LuaDLL.lua_pushstring(L, "typeof"); LuaDLL.lua_pushcfunction(L, GetClassType); LuaDLL.lua_rawset(L, -3); //手动模拟gc //LuaDLL.lua_pushstring(L, "collect"); //LuaDLL.lua_pushcfunction(L, Collect); //LuaDLL.lua_rawset(L, -3); int meta = LuaStatic.GetMetaReference(L, typeof(NullObject)); LuaDLL.lua_pushstring(L, "null"); LuaDLL.tolua_pushnewudata(L, meta, 1); LuaDLL.lua_rawset(L, -3); LuaDLL.lua_pop(L, 1); LuaDLL.tolua_pushudata(L, 1); LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "null"); LuaDLL.lua_pop(L, 1); }
public LuaState() { _L = LuaDLL.luaL_newstate(); LuaDLL.luaL_openlibs(_L); LuaDLL.lua_atpanic(_L, Panic); LuaDLL.lua_pushcfunction(_L, Print); LuaDLL.lua_setglobal(_L, "print"); InitLuaPath(); Debug.Log("InitLuaState"); }
public static void OpenLibs(IntPtr L) { if (!SNG_LUA_DEBUG) { AddLuaLoader(L); } LuaDLL.tolua_atpanic(L, Panic); LuaDLL.tolua_pushcfunction(L, Print); LuaDLL.lua_setglobal(L, "print"); LuaDLL.tolua_pushcfunction(L, DoFile); LuaDLL.lua_setglobal(L, "dofile"); LuaDLL.tolua_pushcfunction(L, LoadFile); LuaDLL.lua_setglobal(L, "loadfile"); LuaDLL.lua_getglobal(L, "tolua"); LuaDLL.lua_pushstring(L, "isnull"); LuaDLL.lua_pushcfunction(L, IsNull); LuaDLL.lua_rawset(L, -3); LuaDLL.lua_pushstring(L, "typeof"); LuaDLL.lua_pushcfunction(L, GetClassType); LuaDLL.lua_rawset(L, -3); LuaDLL.lua_pushstring(L, "tolstring"); LuaDLL.tolua_pushcfunction(L, BufferToString); LuaDLL.lua_rawset(L, -3); LuaDLL.lua_pushstring(L, "toarray"); LuaDLL.tolua_pushcfunction(L, TableToArray); LuaDLL.lua_rawset(L, -3); //手动模拟gc //LuaDLL.lua_pushstring(L, "collect"); //LuaDLL.lua_pushcfunction(L, Collect); //LuaDLL.lua_rawset(L, -3); int meta = LuaStatic.GetMetaReference(L, typeof(NullObject)); LuaDLL.lua_pushstring(L, "null"); LuaDLL.tolua_pushnewudata(L, meta, 1); LuaDLL.lua_rawset(L, -3); LuaDLL.lua_pop(L, 1); LuaDLL.tolua_pushudata(L, 1); LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "null"); #if UNITY_EDITOR GetToLuaInstanceID(); GetConsoleWindowListView(); #endif }
public static bool PCall(IntPtr L, int nargs, int nresult) { int msgHandlerIndex = LuaDLL.lua_gettop(L) - nargs; LuaDLL.lua_pushcfunction(L, LuaFuncs.msgHandler); LuaDLL.lua_insert(L, -nargs - 2); //msghandler,f,nargs int ret = LuaDLL.lua_pcall(L, nargs, nresult, -nargs - 2); if (ret != LuaDLL.LUA_OK) //msghandler,errmsg { LuaDLL.lua_remove(L, -2); Debug.LogError(LuaDLL.lua_tostring(L, -1)); return(false); } LuaDLL.lua_remove(L, msgHandlerIndex); return(true); }
public static void OpenLibs(IntPtr L) { LuaDLL.lua_getglobal(L, "tolua"); LuaDLL.lua_pushstring(L, "isnull"); LuaDLL.lua_pushcfunction(L, new LuaCSFunction(ToLua.IsNull)); LuaDLL.lua_rawset(L, -3); LuaDLL.lua_pushstring(L, "tolstring"); LuaDLL.tolua_pushcfunction(L, new LuaCSFunction(ToLua.BufferToString)); LuaDLL.lua_rawset(L, -3); LuaDLL.lua_pushstring(L, "typeof"); LuaDLL.lua_pushcfunction(L, new LuaCSFunction(ToLua.GetClassType)); LuaDLL.lua_rawset(L, -3); int metaReference = LuaStatic.GetMetaReference(L, typeof(NullObject)); LuaDLL.lua_pushstring(L, "null"); LuaDLL.tolua_pushnewudata(L, metaReference, 1); LuaDLL.lua_rawset(L, -3); LuaDLL.lua_pop(L, 1); LuaDLL.tolua_pushudata(L, 1); LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "null"); }
public static void lua_register(IntPtr luaState, string name, LuaCSFunction func) { LuaDLL.lua_pushcfunction(luaState, func); LuaDLL.lua_setglobal(luaState, name); }