private lua_setmetatable ( |
||
luaState | ||
objIndex | int | |
Результат | int |
public static void lua_setmetatable(IntPtr luaState, string metatable) { LuaDLL.lua_getglobal(luaState, metatable); if (LuaDLL.lua_isnil(luaState, -1)) { LuaDLL.lua_pop(luaState, 1); } else { LuaDLL.lua_setmetatable(luaState, -2); } }
private void createLuaObjectList(IntPtr luaState) { LuaDLL.lua_pushstring(luaState, "luaNet_objects"); LuaDLL.lua_newtable(luaState); LuaDLL.lua_pushvalue(luaState, -1); this.weakTableRef = LuaDLL.luaL_ref(luaState, LuaIndexes.LUA_REGISTRYINDEX); LuaDLL.lua_pushvalue(luaState, -1); LuaDLL.lua_setmetatable(luaState, -2); LuaDLL.lua_pushstring(luaState, "__mode"); LuaDLL.lua_pushstring(luaState, "v"); LuaDLL.lua_settable(luaState, -3); LuaDLL.lua_settable(luaState, LuaIndexes.LUA_REGISTRYINDEX); }
/* * Pushes a new object into the Lua stack with the provided * metatable */ private void pushNewObject(IntPtr luaState, object o, int index, string metatable) { //LuaDLL.luaL_getmetatable(luaState, "luaNet_objects"); LuaDLL.lua_getref(luaState, weakTableRef); LuaDLL.luanet_newudata(luaState, index); if (metatable == "luaNet_metatable") { // Gets or creates the metatable for the object's type //string meta = t.AssemblyQualifiedName //LuaDLL.luaL_getmetatable(luaState, meta); Type t = o.GetType(); PushMetaTable(luaState, o.GetType()); if (LuaDLL.lua_isnil(luaState, -1)) { string meta = t.AssemblyQualifiedName; Debugger.LogError("Create not wrap ulua type:" + meta); LuaDLL.lua_settop(luaState, -2); LuaDLL.luaL_newmetatable(luaState, meta); LuaDLL.lua_pushstring(luaState, "cache"); LuaDLL.lua_newtable(luaState); LuaDLL.lua_rawset(luaState, -3); LuaDLL.lua_pushlightuserdata(luaState, LuaDLL.luanet_gettag()); LuaDLL.lua_pushnumber(luaState, 1); LuaDLL.lua_rawset(luaState, -3); LuaDLL.lua_pushstring(luaState, "__index"); LuaDLL.lua_pushstring(luaState, "luaNet_indexfunction"); LuaDLL.lua_rawget(luaState, (int)LuaIndexes.LUA_REGISTRYINDEX); LuaDLL.lua_rawset(luaState, -3); LuaDLL.lua_pushstring(luaState, "__gc"); LuaDLL.lua_pushstdcallcfunction(luaState, metaFunctions.gcFunction); LuaDLL.lua_rawset(luaState, -3); LuaDLL.lua_pushstring(luaState, "__tostring"); LuaDLL.lua_pushstdcallcfunction(luaState, metaFunctions.toStringFunction); LuaDLL.lua_rawset(luaState, -3); LuaDLL.lua_pushstring(luaState, "__newindex"); LuaDLL.lua_pushstdcallcfunction(luaState, metaFunctions.newindexFunction); LuaDLL.lua_rawset(luaState, -3); } } else { LuaDLL.luaL_getmetatable(luaState, metatable); } LuaDLL.lua_setmetatable(luaState, -2); LuaDLL.lua_pushvalue(luaState, -1); LuaDLL.lua_rawseti(luaState, -3, index); LuaDLL.lua_remove(luaState, -2); }
public static void Register(IntPtr L) { int oldTop = LuaDLL.lua_gettop(L); LuaDLL.lua_getglobal(L, "Director"); if (LuaDLL.lua_isnil(L, -1)) { LuaDLL.lua_pop(L, 1); LuaDLL.lua_newtable(L); LuaDLL.lua_setglobal(L, "Director"); LuaDLL.lua_getglobal(L, "Director"); } LuaDLL.lua_pushstdcallcfunction(L, LuaDirector.GetInstance, "GetInstance"); LuaDLL.lua_pushstdcallcfunction(L, LuaDirector.LogTest, "LogTest"); LuaDLL.lua_pushcsharpproperty(L, "value", LuaDirector.get_value, LuaDirector.set_value); LuaDLL.lua_pushcsharpproperty(L, "luaState", LuaDirector.get_luaState, null); LuaDLL.lua_pushcsharpproperty(L, "scheduler", LuaDirector.get_scheduler, null); LuaDLL.lua_pushcsharpproperty(L, "uiManager", LuaDirector.get_uiManager, null); LuaDLL.lua_pushcsharpproperty(L, "eventDispatcher", LuaDirector.get_eventDispatcher, 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, "MonoBehaviour"); if (LuaDLL.lua_isnil(L, -1)) { LuaDLL.lua_pop(L, 1); LuaDLL.lua_newtable(L); LuaDLL.lua_setglobal(L, "MonoBehaviour"); LuaDLL.lua_getglobal(L, "MonoBehaviour"); LuaDLL.lua_setmetatable(L, -2); } else { LuaDLL.lua_setmetatable(L, -2); } LuaDLL.lua_settop(L, oldTop); LuaStatic.AddTypeDict(typeof(Director)); }
public static int registerTable(IntPtr luaState) { #if __NOGEN__ throwError(luaState, "Tables as Objects not implemnented"); #else ObjectTranslator translator = ObjectTranslator.FromState(luaState); if (LuaDLL.lua_type(luaState, 1) == LuaTypes.LUA_TTABLE) { LuaTable luaTable = translator.getTable(luaState, 1); string superclassName = LuaDLL.lua_tostring(luaState, 2); if (superclassName != null) { Type klass = translator.FindType(superclassName); if (klass != null) { // Creates and pushes the object in the stack, setting // it as the metatable of the first argument object obj = CodeGeneration.Instance.GetClassInstance(klass, luaTable); translator.pushObject(luaState, obj, "luaNet_metatable"); LuaDLL.lua_newtable(luaState); LuaDLL.lua_pushstring(luaState, "__index"); LuaDLL.lua_pushvalue(luaState, -3); LuaDLL.lua_settable(luaState, -3); LuaDLL.lua_pushstring(luaState, "__newindex"); LuaDLL.lua_pushvalue(luaState, -3); LuaDLL.lua_settable(luaState, -3); LuaDLL.lua_setmetatable(luaState, 1); // Pushes the object again, this time as the base field // of the table and with the luaNet_searchbase metatable LuaDLL.lua_pushstring(luaState, "base"); int index = translator.addObject(obj); translator.pushNewObject(luaState, obj, index, "luaNet_searchbase"); LuaDLL.lua_rawset(luaState, 1); } else { translator.throwError(luaState, "register_table: can not find superclass '" + superclassName + "'"); } } else { translator.throwError(luaState, "register_table: superclass name can not be null"); } } else { translator.throwError(luaState, "register_table: first arg is not a table"); } #endif return(0); }
public static void Register(IntPtr L) { int oldTop = LuaDLL.lua_gettop(L); LuaDLL.lua_getglobal(L, "Scheduler"); if (LuaDLL.lua_isnil(L, -1)) { LuaDLL.lua_pop(L, 1); LuaDLL.lua_newtable(L); LuaDLL.lua_setglobal(L, "Scheduler"); LuaDLL.lua_getglobal(L, "Scheduler"); } LuaDLL.lua_pushstdcallcfunction(L, LuaScheduler.MakeInstance, "MakeInstance"); LuaDLL.lua_pushstdcallcfunction(L, LuaScheduler.SchedulerCSFun, "SchedulerCSFun"); LuaDLL.lua_pushstdcallcfunction(L, LuaScheduler.UnSchedulerCSFun, "UnSchedulerCSFun"); LuaDLL.lua_pushstdcallcfunction(L, LuaScheduler.SetTimeOut, "SetTimeOut"); LuaDLL.lua_pushstdcallcfunction(L, LuaScheduler.ExecuteCoroutine, "ExecuteCoroutine"); 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, "MonoBehaviour"); if (LuaDLL.lua_isnil(L, -1)) { LuaDLL.lua_pop(L, 1); LuaDLL.lua_newtable(L); LuaDLL.lua_setglobal(L, "MonoBehaviour"); LuaDLL.lua_getglobal(L, "MonoBehaviour"); LuaDLL.lua_setmetatable(L, -2); } else { LuaDLL.lua_setmetatable(L, -2); } LuaDLL.lua_settop(L, oldTop); LuaStatic.AddTypeDict(typeof(Scheduler)); }
/* * Pushes a new object into the Lua stack with the provided * metatable */ private void pushNewObject(IntPtr luaState, object o, int index, string metatable) { if (metatable == "luaNet_metatable") { // Gets or creates the metatable for the object's type LuaDLL.luaL_getmetatable(luaState, o.GetType().AssemblyQualifiedName); if (LuaDLL.lua_isnil(luaState, -1)) { LuaDLL.lua_settop(luaState, -2); LuaDLL.luaL_newmetatable(luaState, o.GetType().AssemblyQualifiedName); LuaDLL.lua_pushstring(luaState, "cache"); LuaDLL.lua_newtable(luaState); LuaDLL.lua_rawset(luaState, -3); LuaDLL.lua_pushlightuserdata(luaState, LuaDLL.luanet_gettag()); LuaDLL.lua_pushnumber(luaState, 1); LuaDLL.lua_rawset(luaState, -3); LuaDLL.lua_pushstring(luaState, "__index"); LuaDLL.lua_pushstring(luaState, "luaNet_indexfunction"); LuaDLL.lua_rawget(luaState, (int)LuaIndexes.LUA_REGISTRYINDEX); LuaDLL.lua_rawset(luaState, -3); LuaDLL.lua_pushstring(luaState, "__gc"); LuaDLL.lua_pushstdcallcfunction(luaState, metaFunctions.gcFunction); LuaDLL.lua_rawset(luaState, -3); LuaDLL.lua_pushstring(luaState, "__tostring"); LuaDLL.lua_pushstdcallcfunction(luaState, metaFunctions.toStringFunction); LuaDLL.lua_rawset(luaState, -3); LuaDLL.lua_pushstring(luaState, "__newindex"); LuaDLL.lua_pushstdcallcfunction(luaState, metaFunctions.newindexFunction); LuaDLL.lua_rawset(luaState, -3); } } else { LuaDLL.luaL_getmetatable(luaState, metatable); } // Stores the object index in the Lua list and pushes the // index into the Lua stack LuaDLL.luaL_getmetatable(luaState, "luaNet_objects"); LuaDLL.luanet_newudata(luaState, index); LuaDLL.lua_pushvalue(luaState, -3); LuaDLL.lua_remove(luaState, -4); LuaDLL.lua_setmetatable(luaState, -2); LuaDLL.lua_pushvalue(luaState, -1); LuaDLL.lua_rawseti(luaState, -3, index); LuaDLL.lua_remove(luaState, -2); }
/* * Implementation of make_object. Registers a table (first * argument in the stack) as an object subclassing the * type passed as second argument in the stack. */ private int registerTable(KopiLua.Lua.lua_State luaState) { if (LuaDLL.lua_type(luaState, 1) == LuaTypes.LUA_TTABLE) { LuaTable luaTable = getTable(luaState, 1); string superclassName = LuaDLL.lua_tostring(luaState, 2); if (superclassName != null) { Type klass = FindType(superclassName); if (klass != null) { // Creates and pushes the object in the stack, setting // it as the metatable of the first argument object obj = CodeGeneration.Instance.GetClassInstance(klass, luaTable); pushObject(luaState, obj, "luaNet_metatable"); LuaDLL.lua_newtable(luaState); LuaDLL.lua_pushstring(luaState, "__index"); LuaDLL.lua_pushvalue(luaState, -3); LuaDLL.lua_settable(luaState, -3); LuaDLL.lua_pushstring(luaState, "__newindex"); LuaDLL.lua_pushvalue(luaState, -3); LuaDLL.lua_settable(luaState, -3); LuaDLL.lua_setmetatable(luaState, 1); // Pushes the object again, this time as the base field // of the table and with the luaNet_searchbase metatable LuaDLL.lua_pushstring(luaState, "base"); int index = addObject(obj); pushNewObject(luaState, obj, index, "luaNet_searchbase"); LuaDLL.lua_rawset(luaState, 1); } else { throwError(luaState, "register_table: can not find superclass '" + superclassName + "'"); } } else { throwError(luaState, "register_table: superclass name can not be null"); } } else { throwError(luaState, "register_table: first arg is not a table"); } return(0); }
private void pushNewObject(IntPtr luaState, object o, int index, string metatable) { LuaDLL.lua_getref(luaState, this.weakTableRef); LuaDLL.luanet_newudata(luaState, index); if (metatable == "luaNet_metatable") { Type type = o.GetType(); ObjectTranslator.PushMetaTable(luaState, o.GetType()); if (LuaDLL.lua_isnil(luaState, -1)) { string assemblyQualifiedName = type.AssemblyQualifiedName; Debugger.Log("<color=green>Create not wrap ulua type:" + assemblyQualifiedName + "</color>", new object[0]); LuaDLL.lua_settop(luaState, -2); LuaDLL.luaL_newmetatable(luaState, assemblyQualifiedName); LuaDLL.lua_pushstring(luaState, "cache"); LuaDLL.lua_newtable(luaState); LuaDLL.lua_rawset(luaState, -3); LuaDLL.lua_pushlightuserdata(luaState, LuaDLL.luanet_gettag()); LuaDLL.lua_pushnumber(luaState, 1.0); LuaDLL.lua_rawset(luaState, -3); LuaDLL.lua_pushstring(luaState, "__index"); LuaDLL.lua_pushstring(luaState, "luaNet_indexfunction"); LuaDLL.lua_rawget(luaState, LuaIndexes.LUA_REGISTRYINDEX); LuaDLL.lua_rawset(luaState, -3); LuaDLL.lua_pushstring(luaState, "__gc"); LuaDLL.lua_pushstdcallcfunction(luaState, this.metaFunctions.gcFunction, 0); LuaDLL.lua_rawset(luaState, -3); LuaDLL.lua_pushstring(luaState, "__tostring"); LuaDLL.lua_pushstdcallcfunction(luaState, this.metaFunctions.toStringFunction, 0); LuaDLL.lua_rawset(luaState, -3); LuaDLL.lua_pushstring(luaState, "__newindex"); LuaDLL.lua_pushstdcallcfunction(luaState, this.metaFunctions.newindexFunction, 0); LuaDLL.lua_rawset(luaState, -3); } } else { LuaDLL.luaL_getmetatable(luaState, metatable); } LuaDLL.lua_setmetatable(luaState, -2); LuaDLL.lua_pushvalue(luaState, -1); LuaDLL.lua_rawseti(luaState, -3, index); LuaDLL.lua_remove(luaState, -2); }
public static int registerTable(IntPtr luaState) { ObjectTranslator objectTranslator = ObjectTranslator.FromState(luaState); if (LuaDLL.lua_type(luaState, 1) == LuaTypes.LUA_TTABLE) { LuaTable table = objectTranslator.getTable(luaState, 1); string text = LuaDLL.lua_tostring(luaState, 2); if (text != null) { Type type = objectTranslator.FindType(text); if (type != null) { object classInstance = CodeGeneration.Instance.GetClassInstance(type, table); objectTranslator.pushObject(luaState, classInstance, "luaNet_metatable"); LuaDLL.lua_newtable(luaState); LuaDLL.lua_pushstring(luaState, "__index"); LuaDLL.lua_pushvalue(luaState, -3); LuaDLL.lua_settable(luaState, -3); LuaDLL.lua_pushstring(luaState, "__newindex"); LuaDLL.lua_pushvalue(luaState, -3); LuaDLL.lua_settable(luaState, -3); LuaDLL.lua_setmetatable(luaState, 1); LuaDLL.lua_pushstring(luaState, "base"); int index = objectTranslator.addObject(classInstance); objectTranslator.pushNewObject(luaState, classInstance, index, "luaNet_searchbase"); LuaDLL.lua_rawset(luaState, 1); } else { objectTranslator.throwError(luaState, "register_table: can not find superclass '" + text + "'"); } } else { objectTranslator.throwError(luaState, "register_table: superclass name can not be null"); } } else { objectTranslator.throwError(luaState, "register_table: first arg is not a table"); } return(0); }
public void PushNewValueObject(IntPtr luaState, object o, int index) { LuaDLL.luanet_newudata(luaState, index); //string meta = GetAQName(o.GetType()); //LuaDLL.luaL_getmetatable(luaState, meta); Type t = o.GetType(); PushMetaTable(luaState, o.GetType()); if (LuaDLL.lua_isnil(luaState, -1)) { string meta = t.AssemblyQualifiedName; #if UNITY_EDITOR //Debugger.LogWarning("Create not wrap ulua type:" + meta); #endif LuaDLL.lua_settop(luaState, -2); LuaDLL.luaL_newmetatable(luaState, meta); LuaDLL.lua_pushstring(luaState, "cache"); LuaDLL.lua_newtable(luaState); LuaDLL.lua_rawset(luaState, -3); LuaDLL.lua_pushlightuserdata(luaState, LuaDLL.luanet_gettag()); LuaDLL.lua_pushnumber(luaState, 1); LuaDLL.lua_rawset(luaState, -3); LuaDLL.lua_pushstring(luaState, "__index"); LuaDLL.lua_pushstring(luaState, "luaNet_indexfunction"); LuaDLL.lua_rawget(luaState, (int)LuaIndexes.LUA_REGISTRYINDEX); LuaDLL.lua_rawset(luaState, -3); LuaDLL.lua_pushstring(luaState, "__gc"); LuaDLL.lua_pushstdcallcfunction(luaState, metaFunctions.gcFunction); LuaDLL.lua_rawset(luaState, -3); LuaDLL.lua_pushstring(luaState, "__tostring"); LuaDLL.lua_pushstdcallcfunction(luaState, metaFunctions.toStringFunction); LuaDLL.lua_rawset(luaState, -3); LuaDLL.lua_pushstring(luaState, "__newindex"); LuaDLL.lua_pushstdcallcfunction(luaState, metaFunctions.newindexFunction); LuaDLL.lua_rawset(luaState, -3); } LuaDLL.lua_setmetatable(luaState, -2); }
public static int unregisterTable(IntPtr luaState) { ObjectTranslator translator = ObjectTranslator.FromState(luaState); try { if (LuaDLL.lua_getmetatable(luaState, 1) != 0) { LuaDLL.lua_pushstring(luaState, "__index"); LuaDLL.lua_gettable(luaState, -2); object obj = translator.getRawNetObject(luaState, -1); if (obj == null) { translator.throwError(luaState, "unregister_table: arg is not valid table"); } FieldInfo luaTableField = obj.GetType().GetField("__luaInterface_luaTable"); if (luaTableField == null) { translator.throwError(luaState, "unregister_table: arg is not valid table"); } luaTableField.SetValue(obj, null); LuaDLL.lua_pushnil(luaState); LuaDLL.lua_setmetatable(luaState, 1); LuaDLL.lua_pushstring(luaState, "base"); LuaDLL.lua_pushnil(luaState); LuaDLL.lua_settable(luaState, 1); } else { translator.throwError(luaState, "unregister_table: arg is not valid table"); } } catch (Exception e) { translator.throwError(luaState, e.Message); } return(0); }
/* * Implementation of free_object. Clears the metatable and the * base field, freeing the created object for garbage-collection */ private int unregisterTable(KopiLua.Lua.lua_State luaState) { try { if (LuaDLL.lua_getmetatable(luaState, 1) != 0) { LuaDLL.lua_pushstring(luaState, "__index"); LuaDLL.lua_gettable(luaState, -2); object obj = getRawNetObject(luaState, -1); if (obj == null) { throwError(luaState, "unregister_table: arg is not valid table"); } FieldInfo luaTableField = obj.GetType().GetField("__luaInterface_luaTable"); if (luaTableField == null) { throwError(luaState, "unregister_table: arg is not valid table"); } luaTableField.SetValue(obj, null); LuaDLL.lua_pushnil(luaState); LuaDLL.lua_setmetatable(luaState, 1); LuaDLL.lua_pushstring(luaState, "base"); LuaDLL.lua_pushnil(luaState); LuaDLL.lua_settable(luaState, 1); } else { throwError(luaState, "unregister_table: arg is not valid table"); } } catch (Exception e) { throwError(luaState, e.Message); } return(0); }
/* * Pushes a new object into the Lua stack with the provided * metatable */ private void pushNewObject(IntPtr luaState, object o, int index, string metatable) { CreateMetaTable(luaState, o, metatable); // Stores the object index in the Lua list and pushes the index into the Lua stack //if (!o.GetType().IsValueType) //{ LuaDLL.luaL_getmetatable(luaState, "luaNet_objects"); LuaDLL.luanet_newudata(luaState, index); LuaDLL.lua_pushvalue(luaState, -3); LuaDLL.lua_remove(luaState, -4); LuaDLL.lua_setmetatable(luaState, -2); LuaDLL.lua_pushvalue(luaState, -1); LuaDLL.lua_rawseti(luaState, -3, index); LuaDLL.lua_remove(luaState, -2); //} //else //{ // LuaDLL.luanet_newudata(luaState, index); // LuaDLL.lua_pushvalue(luaState, -2); // LuaDLL.lua_remove(luaState, -3); // LuaDLL.lua_setmetatable(luaState, -2); //} }
public void LuaSetMetaTable(int objIndex) { LuaDLL.lua_setmetatable(L, objIndex); }
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 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)); }
//L: [namespace Table] public bool AddObject(IntPtr L, System.Object obj, string metatable /* nullable */) { IntPtr userdata = IntPtr.Zero; if (luaObjs.TryGetValue(obj, out userdata)) { LuaDLL.lua_rawgeti(L, LuaDLL.LUA_REGISTRYINDEX, weakRefForUserData); //namespace,reftable LuaDLL.lua_pushlightuserdata(L, userdata); //namespace,reftable,userdataKey LuaDLL.lua_rawget(L, -2); //namespace,reftable,userdata LuaDLL.lua_remove(L, -2); //namespace,userdata if (LuaDLL.lua_isuserdata(L, -1)) { return(true); } else { LuaDLL.lua_pop(L, 1); //namespace } } userdata = LuaDLL.lua_newuserdata(L, 1); //namespace,obj if (metatable == null) { Type type = obj.GetType(); while (type != null) { LuaDLL.wlua_getfield(L, -2, type.Name); //namespace,obj,typet if (LuaDLL.lua_isnil(L, -1)) { LuaDLL.lua_pop(L, 1); //namespace,obj type = type.BaseType; continue; } if (LuaDLL.lua_istable(L, -1)) { metatable = type.Name; break; } else { LuaDLL.lua_pop(L, 2); //namespace throw new LuaException(L, "metatable must be a table:" + type.Name); } } } else { LuaDLL.wlua_getfield(L, -2, metatable); //namespace,obj,typet if (LuaDLL.lua_isnil(L, -1)) { LuaDLL.lua_pop(L, 2); //namespace throw new LuaException(L, "failed to find metatable:" + metatable); } } //namespace,obj,typet LuaDLL.lua_setmetatable(L, -2); //namespace,obj objs[userdata.ToInt64()] = obj; luaObjs[obj] = userdata; LuaDLL.lua_rawgeti(L, LuaDLL.LUA_REGISTRYINDEX, weakRefForUserData); //namespace,obj,reftable LuaDLL.lua_pushlightuserdata(L, userdata); //namespace,obj,reftable,userdatakey LuaDLL.lua_pushvalue(L, -3); //namespace,obj,reftable,userdatakey,obj LuaDLL.lua_rawset(L, -3); //namespace,obj,reftable LuaDLL.lua_pop(L, 1); //namespace,obj return(true); }