private static void Resetzstrings(RealStatePtr L) { int gen_param_count = LuaAPI.lua_gettop(L); for (int index = 3; index <= gen_param_count; index++) { zstring zstr = null; LuaTypes type = LuaAPI.lua_type(L, index); if (LuaAPI.lua_isint64(L, index)) { zstr = LuaAPI.lua_toint64(L, index); } else if (LuaAPI.lua_isinteger(L, index)) { zstr = LuaAPI.xlua_tointeger(L, index); } else if (LuaAPI.lua_isnumber(L, index)) { zstr = (float)LuaAPI.lua_tonumber(L, index); } else if (LuaTypes.LUA_TBOOLEAN == type) { zstr = LuaAPI.lua_toboolean(L, index); } else if (LuaTypes.LUA_TSTRING == type) { zstr = lua_tozstring(L, index); } zstrings[index - 3] = zstr; } }
public static int GetGenericMethod(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); Type type = getType(L, translator, 1); if (type == null) { return(LuaAPI.luaL_error(L, "xlua.get_generic_method, can not find c# type")); } string methodName = LuaAPI.lua_tostring(L, 2); if (string.IsNullOrEmpty(methodName)) { return(LuaAPI.luaL_error(L, "xlua.get_generic_method, #2 param need a string")); } System.Collections.Generic.List <MethodInfo> matchMethods = new System.Collections.Generic.List <MethodInfo>(); var allMethods = type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance); for (int i = 0; i < allMethods.Length; i++) { var method = allMethods[i]; if (method.Name == methodName && method.IsGenericMethodDefinition) { matchMethods.Add(method); } } int methodIdx = 0; if (matchMethods.Count == 0) { LuaAPI.lua_pushnil(L); } else { if (LuaAPI.lua_isinteger(L, 3)) { methodIdx = LuaAPI.xlua_tointeger(L, 3); } translator.PushAny(L, matchMethods[methodIdx]); LuaAPI.lua_pushstdcallcfunction(L, GenericMethodWraper, 1); } } catch (Exception e) { return(LuaAPI.luaL_error(L, "c# exception in xlua.get_generic_method: " + e)); } return(1); }
private object getObject(RealStatePtr L, int idx, object target) { //return translator.getObject(L, idx); //TODO: translator.getObject move to here?? LuaTypes type = (LuaTypes)LuaAPI.lua_type(L, idx); switch (type) { case LuaTypes.LUA_TNUMBER: { if (LuaAPI.lua_isint64(L, idx)) { return(LuaAPI.lua_toint64(L, idx)); } else if (LuaAPI.lua_isinteger(L, idx)) { return(LuaAPI.xlua_tointeger(L, idx)); } else { return(LuaAPI.lua_tonumber(L, idx)); } } case LuaTypes.LUA_TSTRING: { return(LuaAPI.lua_tostring(L, idx)); } case LuaTypes.LUA_TBOOLEAN: { return(LuaAPI.lua_toboolean(L, idx)); } case LuaTypes.LUA_TTABLE: { return(getLuaTable(L, idx, null)); } case LuaTypes.LUA_TFUNCTION: { return(getLuaFunction(L, idx, null)); } case LuaTypes.LUA_TUSERDATA: { if (LuaAPI.lua_isint64(L, idx)) { return(LuaAPI.lua_toint64(L, idx)); } else if (LuaAPI.lua_isuint64(L, idx)) { return(LuaAPI.lua_touint64(L, idx)); } else { return(translator.SafeGetCSObj(L, idx)); } } default: return(null); } }