3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
28 #include "environment.h"
30 #include "util/pointedthing.h"
33 Server* get_server(lua_State *L);
34 ServerEnvironment* get_env(lua_State *L);
36 void warn_if_field_exists(lua_State *L, int table,
37 const char *fieldname, const std::string &message);
39 ToolCapabilities read_tool_capabilities (lua_State *L, int table);
40 void push_tool_capabilities (lua_State *L,
41 const ToolCapabilities &prop);
42 void set_tool_capabilities (lua_State *L, int table,
43 const ToolCapabilities &toolcap);
45 void realitycheck (lua_State *L);
47 void push_pointed_thing (lua_State *L,
48 const PointedThing& pointed);
50 void stackDump (lua_State *L, std::ostream &o);
58 StackUnroller(lua_State *L):
62 m_original_top = lua_gettop(m_lua); // store stack height
66 lua_settop(m_lua, m_original_top); // restore stack height
71 // What scriptapi_run_callbacks does with the return values of callbacks.
72 // Regardless of the mode, if only one callback is defined,
73 // its return value is the total return value.
74 // Modes only affect the case where 0 or >= 2 callbacks are defined.
77 // Returns the return value of the first callback
78 // Returns nil if list of callbacks is empty
79 RUN_CALLBACKS_MODE_FIRST,
80 // Returns the return value of the last callback
81 // Returns nil if list of callbacks is empty
82 RUN_CALLBACKS_MODE_LAST,
83 // If any callback returns a false value, the first such is returned
84 // Otherwise, the first callback's return value (trueish) is returned
85 // Returns true if list of callbacks is empty
86 RUN_CALLBACKS_MODE_AND,
87 // Like above, but stops calling callbacks (short circuit)
88 // after seeing the first false value
89 RUN_CALLBACKS_MODE_AND_SC,
90 // If any callback returns a true value, the first such is returned
91 // Otherwise, the first callback's return value (falseish) is returned
92 // Returns false if list of callbacks is empty
93 RUN_CALLBACKS_MODE_OR,
94 // Like above, but stops calling callbacks (short circuit)
95 // after seeing the first true value
96 RUN_CALLBACKS_MODE_OR_SC,
97 // Note: "a true value" and "a false value" refer to values that
98 // are converted by lua_toboolean to true or false, respectively.
107 bool string_to_enum(const EnumString *spec, int &result,
108 const std::string &str);
110 int getenumfield(lua_State *L, int table,
111 const char *fieldname, const EnumString *spec, int default_);
112 #endif /* LUA_COMMON_H_ */