3 Copyright (C) 2013 PilzAdam <pilzadam@minetest.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "common/c_content.h"
23 #include "lua_api/l_base.h"
27 class LuaSettings : public ModApiBase
30 static const char className[];
31 static const luaL_Reg methods[];
34 static int gc_object(lua_State *L);
36 // get(self, key) -> value
37 static int l_get(lua_State *L);
39 // get_bool(self, key) -> boolean
40 static int l_get_bool(lua_State *L);
42 // get_np_group(self, key) -> noiseparam
43 static int l_get_np_group(lua_State *L);
45 // set(self, key, value)
46 static int l_set(lua_State *L);
48 // set_bool(self, key, value)
49 static int l_set_bool(lua_State *L);
51 // set_np_group(self, key, value)
52 static int l_set_np_group(lua_State *L);
54 // remove(self, key) -> success
55 static int l_remove(lua_State *L);
57 // get_names(self) -> {key1, ...}
58 static int l_get_names(lua_State *L);
60 // write(self) -> success
61 static int l_write(lua_State *L);
63 // to_table(self) -> {[key1]=value1,...}
64 static int l_to_table(lua_State *L);
66 Settings *m_settings = nullptr;
67 std::string m_filename;
68 bool m_is_own_settings = false;
69 bool m_write_allowed = true;
72 LuaSettings(Settings *settings, const std::string &filename);
73 LuaSettings(const std::string &filename, bool write_allowed);
76 static void create(lua_State *L, Settings *settings, const std::string &filename);
78 // LuaSettings(filename)
79 // Creates a LuaSettings and leaves it on top of the stack
80 static int create_object(lua_State *L);
82 static LuaSettings *checkobject(lua_State *L, int narg);
84 static void Register(lua_State *L);