LuaInterface.ObjectTranslator.getObject C# (CSharp) Method

getObject() private method

private getObject ( IntPtr luaState, int index ) : object
luaState IntPtr
index int
return object
        internal object getObject(IntPtr luaState,int index)
        {
            LuaTypes type=LuaDLL.lua_type(luaState,index);
            switch(type)
            {
                case LuaTypes.LUA_TNUMBER:
                {
                    return LuaDLL.lua_tonumber(luaState,index);
                }
                case LuaTypes.LUA_TSTRING:
                {
                    return LuaDLL.lua_tostring(luaState,index);
                }
                case LuaTypes.LUA_TBOOLEAN:
                {
                    return LuaDLL.lua_toboolean(luaState,index);
                }
                case LuaTypes.LUA_TTABLE:
                {
                    return getTable(luaState,index);
                }
                case LuaTypes.LUA_TFUNCTION:
                {
                    return getFunction(luaState,index);
                }
                case LuaTypes.LUA_TUSERDATA:
                {
                    int udata=LuaDLL.luanet_tonetobject(luaState,index);
                    if(udata!=-1)
                        return objects[udata];
                    else
                        return getUserData(luaState,index);
                }
                default:
                    return null;
            }
        }

Usage Example

示例#1
0
        /// <summary>
        /// Assuming we have a Lua error string sitting on the stack, throw a C# exception out to the user's app
        /// </summary>
        /// <exception cref="LuaScriptException">Thrown if the script caused an exception</exception>
        void ThrowExceptionFromError(int oldTop)
        {
            object err = translator.getObject(luaState, -1);

            LuaDLL.lua_settop(luaState, oldTop);

            // A pre-wrapped exception - just rethrow it (stack trace of InnerException will be preserved)
            LuaScriptException luaEx = err as LuaScriptException;

            if (luaEx != null)
            {
                throw luaEx;
            }

            // A non-wrapped Lua error (best interpreted as a string) - wrap it and throw it
            if (err == null)
            {
                err = "Unknown Lua Error";
            }
            throw new LuaScriptException(err.ToString(), "");
        }
All Usage Examples Of LuaInterface.ObjectTranslator::getObject