Beispiel #1
0
        /// <summary>
        /// looks in the lua stack top if theres a string on top
        /// if it is a string then it adds it as an error message to the Errors list
        /// Clears the method off the stack by setting the top to 0
        /// </summary>
        public void LogError()
        {
            //log error
            if (Lua.lua_isstring(L, -1) > 0)
            {
                Errors.Add(Lua.lua_tostring(L, -1));
            }

            //clear the stack
            Lua.lua_settop(L, 0);
        }
Beispiel #2
0
        /// <summary>
        /// Pops the value sitting on top of the lua stack
        /// </summary>
        /// <param name="luaType">the lua type of the value that was retrieved from the stack, is stored in this out parameter</param>
        /// <returns>the value popped off the stack</returns>
        public object GetValueOfStack(out int luaType)
        {
            luaType = 0;
            object value = null;

            switch (Lua.lua_type(L, -1))
            {
            case Lua.LUA_TNONE: {
                value   = null;
                luaType = Lua.LUA_TNONE;
                //pop value from stack
                Lua.lua_pop(L, 1);
                break;
            }

            case Lua.LUA_TNIL: {
                value   = null;
                luaType = Lua.LUA_TNIL;
                //pop value from stack
                Lua.lua_pop(L, 1);
                break;
            }

            case Lua.LUA_TSTRING: {
                luaType = Lua.LUA_TSTRING;
                value   = Lua.lua_tostring(L, -1);
                //pop value from stack
                Lua.lua_pop(L, 1);
                break;
            }

            case Lua.LUA_TNUMBER: {
                luaType = Lua.LUA_TNUMBER;
                value   = Lua.lua_tonumber(L, -1);
                //pop value from stack
                Lua.lua_pop(L, 1);
                break;
            }

            case Lua.LUA_TBOOLEAN: {
                luaType = Lua.LUA_TBOOLEAN;
                int intToBool = Lua.lua_toboolean(L, -1);
                value = intToBool > 0 ? true : false;
                //pop value from stack
                Lua.lua_pop(L, 1);
                break;
            }

            case Lua.LUA_TTABLE: {
                luaType = Lua.LUA_TTABLE;
                value   = "table";
                //pop value from stack
                Lua.lua_pop(L, 1);
                break;
            }

            default: {
                value = null;
                //pop value from stack
                Lua.lua_pop(L, 1);
                break;
            }

                //case Lua.LUA_TINTEGER:
                //{
                //    value = Lua.lua_tointeger(m_lua_State, -1);
                //    //pop value from stack
                //    Lua.lua_pop(m_lua_State, 1);
                //    break;
                //}
            }

            return(value);
        }