/* * Registers the global functions used by LuaInterface */ private void setGlobalFunctions(IntPtr luaState) { LuaDLL.lua_pushstdcallcfunction(luaState, metaFunctions.indexFunction); LuaDLL.lua_setglobal(luaState, "get_object_member"); LuaDLL.lua_pushstdcallcfunction(luaState, importTypeFunction); LuaDLL.lua_setglobal(luaState, "import_type"); LuaDLL.lua_pushstdcallcfunction(luaState, loadAssemblyFunction); LuaDLL.lua_setglobal(luaState, "load_assembly"); LuaDLL.lua_pushstdcallcfunction(luaState, registerTableFunction); LuaDLL.lua_setglobal(luaState, "make_object"); LuaDLL.lua_pushstdcallcfunction(luaState, unregisterTableFunction); LuaDLL.lua_setglobal(luaState, "free_object"); LuaDLL.lua_pushstdcallcfunction(luaState, getMethodSigFunction); LuaDLL.lua_setglobal(luaState, "get_method_bysig"); LuaDLL.lua_pushstdcallcfunction(luaState, getConstructorSigFunction); LuaDLL.lua_setglobal(luaState, "get_constructor_bysig"); }
public static void Register(IntPtr L) { int oldTop = LuaDLL.lua_gettop(L); LuaDLL.lua_getglobal(L, "Object"); if (LuaDLL.lua_isnil(L, -1)) { LuaDLL.lua_pop(L, 1); LuaDLL.lua_newtable(L); LuaDLL.lua_setglobal(L, "Object"); LuaDLL.lua_getglobal(L, "Object"); } LuaDLL.lua_pushstdcallcfunction(L, LuaObject.New, "New"); LuaDLL.lua_pushstdcallcfunction(L, LuaObject.Destroy, "Destroy"); LuaDLL.lua_pushstdcallcfunction(L, LuaObject.DestroyImmediate, "DestroyImmediate"); LuaDLL.lua_pushstdcallcfunction(L, LuaObject.FindObjectsOfType, "FindObjectsOfType"); LuaDLL.lua_pushstdcallcfunction(L, LuaObject.DontDestroyOnLoad, "DontDestroyOnLoad"); LuaDLL.lua_pushstdcallcfunction(L, LuaObject.DestroyObject, "DestroyObject"); LuaDLL.lua_pushstdcallcfunction(L, LuaObject.ToString, "ToString"); LuaDLL.lua_pushstdcallcfunction(L, LuaObject.Equals, "Equals"); LuaDLL.lua_pushstdcallcfunction(L, LuaObject.GetHashCode, "GetHashCode"); LuaDLL.lua_pushstdcallcfunction(L, LuaObject.GetInstanceID, "GetInstanceID"); LuaDLL.lua_pushstdcallcfunction(L, LuaObject.Instantiate, "Instantiate"); LuaDLL.lua_pushstdcallcfunction(L, LuaObject.FindObjectOfType, "FindObjectOfType"); LuaDLL.lua_pushcsharpproperty(L, "name", LuaObject.get_name, LuaObject.set_name); LuaDLL.lua_pushcsharpproperty(L, "hideFlags", LuaObject.get_hideFlags, LuaObject.set_hideFlags); LuaDLL.lua_getglobal(L, "readIndex"); LuaDLL.lua_pushvalue(L, -1); LuaDLL.lua_setfield(L, -3, "__index"); LuaDLL.lua_pop(L, 1); LuaDLL.lua_getglobal(L, "writeIndex"); LuaDLL.lua_pushvalue(L, -1); LuaDLL.lua_setfield(L, -3, "__newindex"); LuaDLL.lua_pop(L, 1); LuaDLL.lua_pushstdcallcfunction(L, new LuaCSFunction(LuaStatic.GameObjectGC)); LuaDLL.lua_setfield(L, -2, "__gc"); LuaDLL.lua_settop(L, oldTop); LuaStatic.AddTypeDict(typeof(UnityEngine.Object)); }
private void setGlobalFunctions(IntPtr luaState) { LuaDLL.lua_pushstdcallcfunction(luaState, this.metaFunctions.indexFunction, 0); LuaDLL.lua_setglobal(luaState, "get_object_member"); LuaDLL.lua_pushstdcallcfunction(luaState, this.importTypeFunction, 0); LuaDLL.lua_setglobal(luaState, "import_type"); LuaDLL.lua_pushstdcallcfunction(luaState, this.loadAssemblyFunction, 0); LuaDLL.lua_setglobal(luaState, "load_assembly"); LuaDLL.lua_pushstdcallcfunction(luaState, this.registerTableFunction, 0); LuaDLL.lua_setglobal(luaState, "make_object"); LuaDLL.lua_pushstdcallcfunction(luaState, this.unregisterTableFunction, 0); LuaDLL.lua_setglobal(luaState, "free_object"); LuaDLL.lua_pushstdcallcfunction(luaState, this.getMethodSigFunction, 0); LuaDLL.lua_setglobal(luaState, "get_method_bysig"); LuaDLL.lua_pushstdcallcfunction(luaState, this.getConstructorSigFunction, 0); LuaDLL.lua_setglobal(luaState, "get_constructor_bysig"); LuaDLL.lua_pushstdcallcfunction(luaState, this.ctypeFunction, 0); LuaDLL.lua_setglobal(luaState, "ctype"); LuaDLL.lua_pushstdcallcfunction(luaState, this.enumFromIntFunction, 0); LuaDLL.lua_setglobal(luaState, "enum"); }
/* * Indexer for global variables from the LuaInterpreter * Supports navigation of tables by using . operator */ public object this[string fullPath] { get { lock (this) { object returnValue = null; int oldTop = LuaDLL.lua_gettop(luaState); string[] path = fullPath.Split(new char[] { '.' }); LuaDLL.lua_getglobal(luaState, path[0]); returnValue = translator.getObject(luaState, -1); if (path.Length > 1) { string[] remainingPath = new string[path.Length - 1]; Array.Copy(path, 1, remainingPath, 0, path.Length - 1); returnValue = getObject(remainingPath); } LuaDLL.lua_settop(luaState, oldTop); return(returnValue); } } set { int oldTop = LuaDLL.lua_gettop(luaState); string[] path = fullPath.Split(new char[] { '.' }); if (path.Length == 1) { translator.push(luaState, value); LuaDLL.lua_setglobal(luaState, fullPath); } else { LuaDLL.lua_getglobal(luaState, path[0]); string[] remainingPath = new string[path.Length - 1]; Array.Copy(path, 1, remainingPath, 0, path.Length - 1); setObject(remainingPath, value); } LuaDLL.lua_settop(luaState, oldTop); } }
public static void Register(IntPtr L) { int oldTop = LuaDLL.lua_gettop(L); LuaDLL.lua_getglobal(L, "Resources"); if (LuaDLL.lua_isnil(L, -1)) { LuaDLL.lua_pop(L, 1); LuaDLL.lua_newtable(L); LuaDLL.lua_setglobal(L, "Resources"); LuaDLL.lua_getglobal(L, "Resources"); } LuaDLL.lua_pushstdcallcfunction(L, LuaResources.New, "New"); LuaDLL.lua_pushstdcallcfunction(L, LuaResources.FindObjectsOfTypeAll, "FindObjectsOfTypeAll"); LuaDLL.lua_pushstdcallcfunction(L, LuaResources.Load, "Load"); LuaDLL.lua_pushstdcallcfunction(L, LuaResources.LoadAsync, "LoadAsync"); LuaDLL.lua_pushstdcallcfunction(L, LuaResources.LoadAll, "LoadAll"); LuaDLL.lua_pushstdcallcfunction(L, LuaResources.GetBuiltinResource, "GetBuiltinResource"); LuaDLL.lua_pushstdcallcfunction(L, LuaResources.UnloadAsset, "UnloadAsset"); LuaDLL.lua_pushstdcallcfunction(L, LuaResources.UnloadUnusedAssets, "UnloadUnusedAssets"); LuaDLL.lua_getglobal(L, "readIndex"); LuaDLL.lua_pushvalue(L, -1); LuaDLL.lua_setfield(L, -3, "__index"); LuaDLL.lua_pop(L, 1); LuaDLL.lua_getglobal(L, "writeIndex"); LuaDLL.lua_pushvalue(L, -1); LuaDLL.lua_setfield(L, -3, "__newindex"); LuaDLL.lua_pop(L, 1); LuaDLL.lua_pushstdcallcfunction(L, new LuaCSFunction(LuaStatic.GameObjectGC)); LuaDLL.lua_setfield(L, -2, "__gc"); LuaDLL.lua_settop(L, oldTop); LuaStatic.AddTypeDict(typeof(UnityEngine.Resources)); }
public Lua() { luaState = LuaDLL.luaL_newstate(); translator = new ObjectTranslator(this, luaState); LuaDLL.luaL_openlibs(luaState); LuaDLL.lua_pushstring(luaState, "LUAINTERFACE LOADED"); LuaDLL.lua_pushboolean(luaState, true); LuaDLL.lua_settable(luaState, (int)LuaIndexes.LUA_REGISTRYINDEX); LuaDLL.lua_newtable(luaState); LuaDLL.lua_setglobal(luaState, "luanet"); LuaDLL.lua_pushvalue(luaState, (int)LuaIndexes.LUA_GLOBALSINDEX); LuaDLL.lua_getglobal(luaState, "luanet"); LuaDLL.lua_pushstring(luaState, "getmetatable"); LuaDLL.lua_getglobal(luaState, "getmetatable"); LuaDLL.lua_settable(luaState, -3); LuaDLL.lua_replace(luaState, (int)LuaIndexes.LUA_GLOBALSINDEX); LuaDLL.lua_replace(luaState, (int)LuaIndexes.LUA_GLOBALSINDEX); LuaDLL.luaL_dostring(luaState, Lua.init_luanet); panicCallback = new LuaCSFunction(PanicCallback); LuaDLL.lua_atpanic(luaState, panicCallback); }
/* * Creates a new table as a global variable or as a field * inside an existing table */ public void NewTable(string fullPath) { string[] path = fullPath.Split('.'); int oldTop = LuaDLL.lua_gettop(L); if (path.Length == 1) { LuaDLL.lua_newtable(L); LuaDLL.lua_setglobal(L, fullPath); } else { LuaDLL.lua_getglobal(L, path[0]); for (int i = 1; i < path.Length - 1; i++) { LuaDLL.lua_pushstring(L, path[i]); LuaDLL.lua_gettable(L, -2); } LuaDLL.lua_pushstring(L, path[path.Length - 1]); LuaDLL.lua_newtable(L); LuaDLL.lua_settable(L, -3); } LuaDLL.lua_settop(L, oldTop); }
/* * Creates a new table as a global variable or as a field * inside an existing table */ public void NewTable(string fullPath) { string[] path = fullPath.Split(new char[] { '.' }); int oldTop = LuaDLL.lua_gettop(luaState); if (path.Length == 1) { LuaDLL.lua_newtable(luaState); LuaDLL.lua_setglobal(luaState, fullPath); } else { LuaDLL.lua_getglobal(luaState, path[0]); for (int i = 1; i < path.Length - 1; i++) { LuaDLL.lua_pushstring(luaState, path[i]); LuaDLL.lua_gettable(luaState, -2); } LuaDLL.lua_pushstring(luaState, path[path.Length - 1]); LuaDLL.lua_newtable(luaState); LuaDLL.lua_settable(luaState, -3); } LuaDLL.lua_settop(luaState, oldTop); }
public Lua() { luaState = LuaDLL.luaL_newstate(); // steffenj: Lua 5.1.1 API change (lua_open is gone) //LuaDLL.luaopen_base(luaState); // steffenj: luaopen_* no longer used LuaDLL.luaL_openlibs(luaState); // steffenj: Lua 5.1.1 API change (luaopen_base is gone, just open all libs right here) LuaDLL.lua_pushstring(luaState, "LUAINTERFACE LOADED"); LuaDLL.lua_pushboolean(luaState, true); LuaDLL.lua_settable(luaState, LuaIndexes.LUA_REGISTRYINDEX); LuaDLL.lua_newtable(luaState); LuaDLL.lua_setglobal(luaState, "luanet"); LuaDLL.lua_pushvalue(luaState, LuaIndexes.LUA_GLOBALSINDEX); LuaDLL.lua_getglobal(luaState, "luanet"); LuaDLL.lua_pushstring(luaState, "getmetatable"); LuaDLL.lua_getglobal(luaState, "getmetatable"); LuaDLL.lua_settable(luaState, -3); LuaDLL.lua_replace(luaState, LuaIndexes.LUA_GLOBALSINDEX); translator = new ObjectTranslator(this, luaState); LuaDLL.lua_replace(luaState, LuaIndexes.LUA_GLOBALSINDEX); LuaDLL.luaL_dostring(luaState, Lua.init_luanet); // steffenj: lua_dostring renamed to luaL_dostring // We need to keep this in a managed reference so the delegate doesn't get garbage collected panicCallback = new LuaFunctionCallback(PanicCallback); LuaDLL.lua_atpanic(luaState, panicCallback); }
/* * Indexer for global variables from the LuaInterpreter * Supports navigation of tables by using . operator */ public object this[string fullPath] { get { object returnValue = null; int oldTop = LuaDLL.lua_gettop(L); string[] path = fullPath.Split('.'); LuaDLL.lua_getglobal(L, path[0]); returnValue = translator.GetObject(L, -1); if (path.Length > 1) { string[] remainingPath = new string[path.Length - 1]; Array.Copy(path, 1, remainingPath, 0, path.Length - 1); returnValue = getObject(remainingPath); } LuaDLL.lua_settop(L, oldTop); return(returnValue); } set { int oldTop = LuaDLL.lua_gettop(L); string[] path = fullPath.Split('.'); if (path.Length == 1) { translator.Push(L, value); LuaDLL.lua_setglobal(L, fullPath); } else { //LuaDLL.lua_getglobal(L, path[0]); LuaDLL.lua_rawglobal(L, path[0]); LuaTypes type = LuaDLL.lua_type(L, -1); if (type == LuaTypes.LUA_TNIL) { //Debugger.LogError("Table {0} not exists", path[0]); LuaDLL.lua_settop(L, oldTop); return; } string[] remainingPath = new string[path.Length - 1]; Array.Copy(path, 1, remainingPath, 0, path.Length - 1); setObject(remainingPath, value); } LuaDLL.lua_settop(L, oldTop); // Globals auto-complete // comment by topameng, too many time cost, you shound register you type in other position /*if (value == null) * { * // Remove now obsolete entries * globals.Remove(fullPath); * } * else * { * // Add new entries * if (!globals.Contains(fullPath)) * registerGlobal(fullPath, value.GetType(), 0); * }*/ } }
public LuaState() { // Create State L = LuaDLL.luaL_newstate(); // Create LuaInterface library LuaDLL.luaL_openlibs(L); LuaDLL.lua_pushstring(L, "LUAINTERFACE LOADED"); LuaDLL.lua_pushboolean(L, true); LuaDLL.lua_settable(L, (int)LuaIndexes.LUA_REGISTRYINDEX); LuaDLL.lua_newtable(L); LuaDLL.lua_setglobal(L, "luanet"); LuaDLL.lua_pushvalue(L, (int)LuaIndexes.LUA_GLOBALSINDEX); //鍘嬪叆浜哶G琛? LuaDLL.lua_getglobal(L, "luanet"); LuaDLL.lua_pushstring(L, "getmetatable"); LuaDLL.lua_getglobal(L, "getmetatable"); LuaDLL.lua_settable(L, -3); LuaDLL.lua_pushstring(L, "rawget"); LuaDLL.lua_getglobal(L, "rawget"); LuaDLL.lua_settable(L, -3); LuaDLL.lua_pushstring(L, "rawset"); LuaDLL.lua_getglobal(L, "rawset"); LuaDLL.lua_settable(L, -3); // Set luanet as global for object translator LuaDLL.lua_replace(L, (int)LuaIndexes.LUA_GLOBALSINDEX); //鐢╨uanet鏇挎崲_G琛? translator = new ObjectTranslator(this, L); LuaDLL.lua_replace(L, (int)LuaIndexes.LUA_GLOBALSINDEX); //鎭㈠_G琛? translator.PushTranslator(L); // We need to keep this in a managed reference so the delegate doesn't get garbage collected panicCallback = new LuaCSFunction(LuaStatic.panic); LuaDLL.lua_atpanic(L, panicCallback); printFunction = new LuaCSFunction(LuaStatic.print); LuaDLL.lua_pushstdcallcfunction(L, printFunction); LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "lprint"); warnFunction = new LuaCSFunction(LuaStatic.warn); LuaDLL.lua_pushstdcallcfunction(L, warnFunction); LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "lwarn"); breakFunction = new LuaCSFunction(LuaStatic.breakFunc); LuaDLL.lua_pushstdcallcfunction(L, breakFunction); LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "breakpoint"); loadfileFunction = new LuaCSFunction(LuaStatic.loadfile); LuaDLL.lua_pushstdcallcfunction(L, loadfileFunction); LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "loadfile"); dofileFunction = new LuaCSFunction(LuaStatic.dofile); LuaDLL.lua_pushstdcallcfunction(L, dofileFunction); LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "dofile"); pcallFunction = new LuaCSFunction(LuaStatic.pcall); LuaDLL.lua_pushstdcallcfunction(L, pcallFunction); LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "pcall"); LuaDLL.lua_pushstdcallcfunction(L, LuaStatic.errorFunc_traceback); errorFuncRef = LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX); // Insert our loader FIRST loaderFunction = new LuaCSFunction(LuaStatic.loader); LuaDLL.lua_pushstdcallcfunction(L, loaderFunction); int loaderFunc = LuaDLL.lua_gettop(L); LuaDLL.lua_getfield(L, LuaIndexes.LUA_GLOBALSINDEX, "package"); LuaDLL.lua_getfield(L, -1, "loaders"); int loaderTable = LuaDLL.lua_gettop(L); // Shift table elements right for (int e = LuaDLL.luaL_getn(L, loaderTable) + 1; e > 1; e--) { LuaDLL.lua_rawgeti(L, loaderTable, e - 1); LuaDLL.lua_rawseti(L, loaderTable, e); } LuaDLL.lua_pushvalue(L, loaderFunc); LuaDLL.lua_rawseti(L, loaderTable, 1); LuaDLL.lua_settop(L, 0); DoString(LuaStatic.init_luanet); tracebackFunction = new LuaCSFunction(LuaStatic.traceback); }
public void LuaSetGlobal(string name) { LuaDLL.lua_setglobal(L, name); }
public static void Register(IntPtr L) { int oldTop = LuaDLL.lua_gettop(L); LuaDLL.lua_getglobal(L, "GameObject"); if (LuaDLL.lua_isnil(L, -1)) { LuaDLL.lua_pop(L, 1); LuaDLL.lua_newtable(L); LuaDLL.lua_setglobal(L, "GameObject"); LuaDLL.lua_getglobal(L, "GameObject"); } LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.New, "New"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.CreatePrimitive, "CreatePrimitive"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.GetComponent, "GetComponent"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.GetComponentInChildren, "GetComponentInChildren"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.GetComponentInParent, "GetComponentInParent"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.GetComponents, "GetComponents"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.GetComponentsInChildren, "GetComponentsInChildren"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.GetComponentsInParent, "GetComponentsInParent"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.SetActive, "SetActive"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.CompareTag, "CompareTag"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.FindGameObjectWithTag, "FindGameObjectWithTag"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.FindWithTag, "FindWithTag"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.FindGameObjectsWithTag, "FindGameObjectsWithTag"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.SendMessageUpwards, "SendMessageUpwards"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.SendMessage, "SendMessage"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.BroadcastMessage, "BroadcastMessage"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.AddComponent, "AddComponent"); LuaDLL.lua_pushstdcallcfunction(L, LuaGameObject.Find, "Find"); LuaDLL.lua_pushcsharpproperty(L, "transform", LuaGameObject.get_transform, null); LuaDLL.lua_pushcsharpproperty(L, "layer", LuaGameObject.get_layer, LuaGameObject.set_layer); LuaDLL.lua_pushcsharpproperty(L, "activeSelf", LuaGameObject.get_activeSelf, null); LuaDLL.lua_pushcsharpproperty(L, "activeInHierarchy", LuaGameObject.get_activeInHierarchy, null); LuaDLL.lua_pushcsharpproperty(L, "isStatic", LuaGameObject.get_isStatic, LuaGameObject.set_isStatic); LuaDLL.lua_pushcsharpproperty(L, "tag", LuaGameObject.get_tag, LuaGameObject.set_tag); LuaDLL.lua_pushcsharpproperty(L, "gameObject", LuaGameObject.get_gameObject, null); LuaDLL.lua_getglobal(L, "readIndex"); LuaDLL.lua_pushvalue(L, -1); LuaDLL.lua_setfield(L, -3, "__index"); LuaDLL.lua_pop(L, 1); LuaDLL.lua_getglobal(L, "writeIndex"); LuaDLL.lua_pushvalue(L, -1); LuaDLL.lua_setfield(L, -3, "__newindex"); LuaDLL.lua_pop(L, 1); LuaDLL.lua_pushstdcallcfunction(L, new LuaCSFunction(LuaStatic.GameObjectGC)); LuaDLL.lua_setfield(L, -2, "__gc"); LuaDLL.lua_getglobal(L, "Object"); if (LuaDLL.lua_isnil(L, -1)) { LuaDLL.lua_pop(L, 1); LuaDLL.lua_newtable(L); LuaDLL.lua_setglobal(L, "Object"); LuaDLL.lua_getglobal(L, "Object"); LuaDLL.lua_setmetatable(L, -2); } else { LuaDLL.lua_setmetatable(L, -2); } LuaDLL.lua_settop(L, oldTop); LuaStatic.AddTypeDict(typeof(UnityEngine.GameObject)); }
public LuaState() { // Create State L = LuaDLL.luaL_newstate(); // Create LuaInterface library LuaDLL.luaL_openlibs(L); LuaDLL.lua_pushstring(L, "LUAINTERFACE LOADED"); LuaDLL.lua_pushboolean(L, true); LuaDLL.lua_settable(L, (int)LuaIndexes.LUA_REGISTRYINDEX); LuaDLL.lua_newtable(L); LuaDLL.lua_setglobal(L, "luanet"); LuaDLL.lua_pushvalue(L, (int)LuaIndexes.LUA_GLOBALSINDEX); LuaDLL.lua_getglobal(L, "luanet"); LuaDLL.lua_pushstring(L, "getmetatable"); LuaDLL.lua_getglobal(L, "getmetatable"); LuaDLL.lua_settable(L, -3); // Set luanet as global for object translator LuaDLL.lua_replace(L, (int)LuaIndexes.LUA_GLOBALSINDEX); translator = new ObjectTranslator(this, L); LuaDLL.lua_replace(L, (int)LuaIndexes.LUA_GLOBALSINDEX); GCHandle handle = GCHandle.Alloc(translator, GCHandleType.Pinned); IntPtr thisptr = GCHandle.ToIntPtr(handle); LuaDLL.lua_pushlightuserdata(L, thisptr); LuaDLL.lua_setglobal(L, "_translator"); // We need to keep this in a managed reference so the delegate doesn't get garbage collected panicCallback = new LuaCSFunction(LuaStatic.panic); LuaDLL.lua_atpanic(L, panicCallback); printFunction = new LuaCSFunction(LuaStatic.print); LuaDLL.lua_pushstdcallcfunction(L, printFunction); LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "print"); loadfileFunction = new LuaCSFunction(LuaStatic.loadfile); LuaDLL.lua_pushstdcallcfunction(L, loadfileFunction); LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "loadfile"); dofileFunction = new LuaCSFunction(LuaStatic.dofile); LuaDLL.lua_pushstdcallcfunction(L, dofileFunction); LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "dofile"); // Insert our loader FIRST loaderFunction = new LuaCSFunction(LuaStatic.loader); LuaDLL.lua_pushstdcallcfunction(L, loaderFunction); int loaderFunc = LuaDLL.lua_gettop(L); LuaDLL.lua_getfield(L, LuaIndexes.LUA_GLOBALSINDEX, "package"); LuaDLL.lua_getfield(L, -1, "loaders"); int loaderTable = LuaDLL.lua_gettop(L); // Shift table elements right for (int e = LuaDLL.luaL_getn(L, loaderTable) + 1; e > 1; e--) { LuaDLL.lua_rawgeti(L, loaderTable, e - 1); LuaDLL.lua_rawseti(L, loaderTable, e); } LuaDLL.lua_pushvalue(L, loaderFunc); LuaDLL.lua_rawseti(L, loaderTable, 1); LuaDLL.lua_settop(L, 0); DoString(LuaStatic.init_luanet); tracebackFunction = new LuaCSFunction(LuaStatic.traceback); }
public static void lua_register(IntPtr luaState, string name, LuaCSFunction func) { LuaDLL.lua_pushcfunction(luaState, func); LuaDLL.lua_setglobal(luaState, name); }
public static void Register(IntPtr L) { int oldTop = LuaDLL.lua_gettop(L); LuaDLL.lua_getglobal(L, "Transform"); if (LuaDLL.lua_isnil(L, -1)) { LuaDLL.lua_pop(L, 1); LuaDLL.lua_newtable(L); LuaDLL.lua_setglobal(L, "Transform"); LuaDLL.lua_getglobal(L, "Transform"); } LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.SetParent, "SetParent"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.Translate, "Translate"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.Rotate, "Rotate"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.RotateAround, "RotateAround"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.LookAt, "LookAt"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.TransformDirection, "TransformDirection"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.InverseTransformDirection, "InverseTransformDirection"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.TransformVector, "TransformVector"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.InverseTransformVector, "InverseTransformVector"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.TransformPoint, "TransformPoint"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.InverseTransformPoint, "InverseTransformPoint"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.DetachChildren, "DetachChildren"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.SetAsFirstSibling, "SetAsFirstSibling"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.SetAsLastSibling, "SetAsLastSibling"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.SetSiblingIndex, "SetSiblingIndex"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.GetSiblingIndex, "GetSiblingIndex"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.Find, "Find"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.IsChildOf, "IsChildOf"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.FindChild, "FindChild"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.GetEnumerator, "GetEnumerator"); LuaDLL.lua_pushstdcallcfunction(L, LuaTransform.GetChild, "GetChild"); LuaDLL.lua_pushcsharpproperty(L, "position", LuaTransform.get_position, LuaTransform.set_position); LuaDLL.lua_pushcsharpproperty(L, "localPosition", LuaTransform.get_localPosition, LuaTransform.set_localPosition); LuaDLL.lua_pushcsharpproperty(L, "eulerAngles", LuaTransform.get_eulerAngles, LuaTransform.set_eulerAngles); LuaDLL.lua_pushcsharpproperty(L, "localEulerAngles", LuaTransform.get_localEulerAngles, LuaTransform.set_localEulerAngles); LuaDLL.lua_pushcsharpproperty(L, "right", LuaTransform.get_right, LuaTransform.set_right); LuaDLL.lua_pushcsharpproperty(L, "up", LuaTransform.get_up, LuaTransform.set_up); LuaDLL.lua_pushcsharpproperty(L, "forward", LuaTransform.get_forward, LuaTransform.set_forward); LuaDLL.lua_pushcsharpproperty(L, "rotation", LuaTransform.get_rotation, LuaTransform.set_rotation); LuaDLL.lua_pushcsharpproperty(L, "localRotation", LuaTransform.get_localRotation, LuaTransform.set_localRotation); LuaDLL.lua_pushcsharpproperty(L, "localScale", LuaTransform.get_localScale, LuaTransform.set_localScale); LuaDLL.lua_pushcsharpproperty(L, "parent", LuaTransform.get_parent, LuaTransform.set_parent); LuaDLL.lua_pushcsharpproperty(L, "worldToLocalMatrix", LuaTransform.get_worldToLocalMatrix, null); LuaDLL.lua_pushcsharpproperty(L, "localToWorldMatrix", LuaTransform.get_localToWorldMatrix, null); LuaDLL.lua_pushcsharpproperty(L, "root", LuaTransform.get_root, null); LuaDLL.lua_pushcsharpproperty(L, "childCount", LuaTransform.get_childCount, null); LuaDLL.lua_pushcsharpproperty(L, "lossyScale", LuaTransform.get_lossyScale, null); LuaDLL.lua_pushcsharpproperty(L, "hasChanged", LuaTransform.get_hasChanged, LuaTransform.set_hasChanged); LuaDLL.lua_getglobal(L, "readIndex"); LuaDLL.lua_pushvalue(L, -1); LuaDLL.lua_setfield(L, -3, "__index"); LuaDLL.lua_pop(L, 1); LuaDLL.lua_getglobal(L, "writeIndex"); LuaDLL.lua_pushvalue(L, -1); LuaDLL.lua_setfield(L, -3, "__newindex"); LuaDLL.lua_pop(L, 1); LuaDLL.lua_pushstdcallcfunction(L, new LuaCSFunction(LuaStatic.GameObjectGC)); LuaDLL.lua_setfield(L, -2, "__gc"); LuaDLL.lua_getglobal(L, "Component"); if (LuaDLL.lua_isnil(L, -1)) { LuaDLL.lua_pop(L, 1); LuaDLL.lua_newtable(L); LuaDLL.lua_setglobal(L, "Component"); LuaDLL.lua_getglobal(L, "Component"); LuaDLL.lua_setmetatable(L, -2); } else { LuaDLL.lua_setmetatable(L, -2); } LuaDLL.lua_settop(L, oldTop); LuaStatic.AddTypeDict(typeof(UnityEngine.Transform)); }