Esempio n. 1
0
        /// <summary>
        /// Gets the value of a field of a table and returns it as type object i.e. return luaTable.someField
        /// After the call the lua stack is balanced
        /// </summary>
        /// <param name="tableName">name of lua table</param>
        /// <param name="fieldName">name of table field</param>
        /// <returns>returns luaTable.someField</returns>
        public object GetTableField(string tableName, string fieldName)
        {
            //push table on the stack
            Lua.lua_getglobal(L, tableName);

            if (IsTopNil)
            {
                throw new Exception("GetTableField, the table does not exist: " + tableName);
            }

            //push table field name on the stack
            Lua.lua_pushstring(L, fieldName);

            //get value of field of table: get tableName[fieldName]
            Lua.lua_gettable(L, -2);

            //get the result of the stack
            int    luaType = 0;
            object value   = GetValueOfStack(out luaType);

            //pop table of the stack
            Lua.lua_pop(L, 1);

            //stack is balanced
            return(value);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the value of a field of a lua table and returns it as type object i.e. return luaTable.someField
        /// The table to operate on must currently be on top of the lua stack.
        /// After the call the lua table is still on top of the stack
        /// </summary>
        /// <param name="fieldName">
        /// the name of the field, belonging to a lua table currently sitting on
        /// top of the lua stack
        /// </param>
        /// <returns>returns luaTable.someField</returns>
        public object GetTableField(string fieldName)
        {
            if (IsTopNil)
            {
                throw new Exception("GetTableField, no table on top of stack");
            }

            //push table field name on the stack
            Lua.lua_pushstring(L, fieldName);

            //get value of field of table: get tableName[fieldName]
            Lua.lua_gettable(L, -2);

            //get the result of the stack
            int    luaType = 0;
            object value   = GetValueOfStack(out luaType);

            //table is still on top of the stack
            return(value);
        }