Exemplo n.º 1
0
        /// <summary>
        /// Gets an object from the Lua stack according to its Lua type.
        /// </summary>
        /// <param name="luaState"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        internal object GetStackObject(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(Encoding.UTF8.GetString(LuaDLL.LuaToByteArray(luaState, index)));
                //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);
            }
        }