MCPcopy Create free account
hub / github.com/Tencent/xLua / XLuaMetatableOperation

Function XLuaMetatableOperation

Assets/XLua/Src/StaticLuaCallbacks.cs:1059–1101  ·  view source on GitHub ↗
(RealStatePtr L)

Source from the content-addressed store, hash-verified

1057 }
1058
1059 [MonoPInvokeCallback(typeof(LuaCSFunction))]
1060 public static int XLuaMetatableOperation(RealStatePtr L)
1061 {
1062 try
1063 {
1064 ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
1065 Type type = getType(L, translator, 1);
1066 if (type == null)
1067 {
1068 return LuaAPI.luaL_error(L, "xlua.metatable_operation, can not find c# type");
1069 }
1070
1071 bool is_first = false;
1072 int type_id = translator.getTypeId(L, type, out is_first);
1073
1074 var param_num = LuaAPI.lua_gettop(L);
1075
1076 if (param_num == 1) //get
1077 {
1078 LuaAPI.xlua_rawgeti(L, LuaIndexes.LUA_REGISTRYINDEX, type_id);
1079 return 1;
1080 }
1081 else if (param_num == 2) //set
1082 {
1083 if (LuaAPI.lua_type(L, 2) != LuaTypes.LUA_TTABLE)
1084 {
1085 return LuaAPI.luaL_error(L, "argument #2 must be a table");
1086 }
1087 LuaAPI.lua_pushnumber(L, type_id);
1088 LuaAPI.xlua_rawseti(L, 2, 1);
1089 LuaAPI.xlua_rawseti(L, LuaIndexes.LUA_REGISTRYINDEX, type_id);
1090 return 0;
1091 }
1092 else
1093 {
1094 return LuaAPI.luaL_error(L, "invalid argument num for xlua.metatable_operation: " + param_num);
1095 }
1096 }
1097 catch (Exception e)
1098 {
1099 return LuaAPI.luaL_error(L, "c# exception in xlua.metatable_operation: " + e);
1100 }
1101 }
1102
1103 [MonoPInvokeCallback(typeof(LuaCSFunction))]
1104 public static int DelegateConstructor(RealStatePtr L)

Callers

nothing calls this directly

Calls 9

FindMethod · 0.80
luaL_errorMethod · 0.80
getTypeIdMethod · 0.80
lua_gettopMethod · 0.80
xlua_rawgetiMethod · 0.80
lua_typeMethod · 0.80
lua_pushnumberMethod · 0.80
xlua_rawsetiMethod · 0.80
getTypeFunction · 0.70

Tested by

no test coverage detected