Allow damage for attached objects, add attach/detach callbacks (#6786)
[oweals/minetest.git] / src / script / lua_api / l_settings.h
1 /*
2 Minetest
3 Copyright (C) 2013 PilzAdam <pilzadam@minetest.net>
4
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.
9
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.
14
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.
18 */
19
20 #pragma once
21
22 #include "common/c_content.h"
23 #include "lua_api/l_base.h"
24
25 class Settings;
26
27 class LuaSettings : public ModApiBase
28 {
29 private:
30         static const char className[];
31         static const luaL_Reg methods[];
32
33         // garbage collector
34         static int gc_object(lua_State *L);
35
36         // get(self, key) -> value
37         static int l_get(lua_State *L);
38
39         // get_bool(self, key) -> boolean
40         static int l_get_bool(lua_State *L);
41
42         // get_np_group(self, key) -> noiseparam
43         static int l_get_np_group(lua_State *L);
44
45         // set(self, key, value)
46         static int l_set(lua_State *L);
47
48         // set_bool(self, key, value)
49         static int l_set_bool(lua_State *L);
50
51         // set_np_group(self, key, value)
52         static int l_set_np_group(lua_State *L);
53
54         // remove(self, key) -> success
55         static int l_remove(lua_State *L);
56
57         // get_names(self) -> {key1, ...}
58         static int l_get_names(lua_State *L);
59
60         // write(self) -> success
61         static int l_write(lua_State *L);
62
63         // to_table(self) -> {[key1]=value1,...}
64         static int l_to_table(lua_State *L);
65
66         Settings *m_settings = nullptr;
67         std::string m_filename;
68         bool m_is_own_settings = false;
69         bool m_write_allowed = true;
70
71 public:
72         LuaSettings(Settings *settings, const std::string &filename);
73         LuaSettings(const std::string &filename, bool write_allowed);
74         ~LuaSettings();
75
76         static void create(lua_State *L, Settings *settings, const std::string &filename);
77
78         // LuaSettings(filename)
79         // Creates a LuaSettings and leaves it on top of the stack
80         static int create_object(lua_State *L);
81
82         static LuaSettings *checkobject(lua_State *L, int narg);
83
84         static void Register(lua_State *L);
85 };