public static int ctype(IntPtr luaState) { ObjectTranslator translator = ObjectTranslator.FromState(luaState); Type t = translator.typeOf(luaState, 1); if (t == null) { return translator.pushError(luaState, "not a CLR class"); } translator.pushObject(luaState, t, "luaNet_metatable"); return 1; }
public static int ctype(IntPtr luaState) { ObjectTranslator objectTranslator = ObjectTranslator.FromState(luaState); Type type = objectTranslator.typeOf(luaState, 1); if (type == null) { return(objectTranslator.pushError(luaState, "not a CLR class")); } objectTranslator.pushObject(luaState, type, "luaNet_metatable"); return(1); }
public static int enumFromInt(IntPtr luaState) { ObjectTranslator translator = ObjectTranslator.FromState(luaState); Type t = translator.typeOf(luaState, 1); if (t == null || !t.IsEnum) { return(translator.pushError(luaState, "not an enum")); } object res = null; LuaTypes lt = LuaDLL.lua_type(luaState, 2); if (lt == LuaTypes.LUA_TNUMBER) { int ival = (int)LuaDLL.lua_tonumber(luaState, 2); res = Enum.ToObject(t, ival); } else if (lt == LuaTypes.LUA_TSTRING) { string sflags = LuaDLL.lua_tostring(luaState, 2); string err = null; try { res = Enum.Parse(t, sflags); } catch (ArgumentException e) { err = e.Message; } if (err != null) { return(translator.pushError(luaState, err)); } } else { return(translator.pushError(luaState, "second argument must be a integer or a string")); } translator.pushObject(luaState, res, "luaNet_metatable"); return(1); }
public static int enumFromInt(IntPtr luaState) { ObjectTranslator objectTranslator = ObjectTranslator.FromState(luaState); Type type = objectTranslator.typeOf(luaState, 1); if (type == null || !type.IsEnum) { return(objectTranslator.pushError(luaState, "not an enum")); } object o = null; LuaTypes luaTypes = LuaDLL.lua_type(luaState, 2); if (luaTypes == LuaTypes.LUA_TNUMBER) { int value = (int)LuaDLL.lua_tonumber(luaState, 2); o = Enum.ToObject(type, value); } else { if (luaTypes != LuaTypes.LUA_TSTRING) { return(objectTranslator.pushError(luaState, "second argument must be a integer or a string")); } string value2 = LuaDLL.lua_tostring(luaState, 2); string text = null; try { o = Enum.Parse(type, value2); } catch (ArgumentException ex) { text = ex.Message; } if (text != null) { return(objectTranslator.pushError(luaState, text)); } } objectTranslator.pushObject(luaState, o, "luaNet_metatable"); return(1); }