Example #1
0
        /*
         * Creates a new table as a global variable or as a field
         * inside an existing table
         */
        public void NewTable(string fullPath)
        {
            string[] path   = fullPath.Split(new char[] { '.' });
            int      oldTop = LuaDLL.lua_gettop(luaState);

            if (path.Length == 1)
            {
                LuaDLL.lua_newtable(luaState);
                LuaDLL.lua_setglobal(luaState, fullPath);
            }
            else
            {
                LuaDLL.lua_getglobal(luaState, path[0]);
                for (int i = 1; i < path.Length - 1; i++)
                {
                    LuaDLL.lua_pushstring(luaState, path[i]);
                    LuaDLL.lua_gettable(luaState, -2);
                }
                LuaDLL.lua_pushstring(luaState, path[path.Length - 1]);
                LuaDLL.lua_newtable(luaState);
                LuaDLL.lua_settable(luaState, -3);
            }
            LuaDLL.lua_settop(luaState, oldTop);
        }