49 #include <boost/range/adaptors.hpp> 59 #define DBG_LUA LOG_STREAM(debug, log_scripting_lua) 60 #define LOG_LUA LOG_STREAM(info, log_scripting_lua) 61 #define WRN_LUA LOG_STREAM(warn, log_scripting_lua) 62 #define ERR_LUA LOG_STREAM(err, log_scripting_lua) 71 std::stringstream line;
121 return "not started";
172 DBG_LUA <<
"loading script from string:\n<<\n" << prog <<
"\n>>\n";
178 std::string
msg = err_str ? err_str :
"null string";
180 std::string context =
"When parsing a string to a lua thread, ";
183 context +=
" a syntax error";
185 context +=
" a memory error";
187 context +=
" an unknown error";
193 throw game::lua_error(
"Error when executing a script to make a lua thread.");
210 throw game::lua_error(
"Error when executing a file to make a lua thread.");
231 if (!backend->valid) {
232 luaL_error(L ,
"Error, you tried to use an invalid context object in a lua thread");
239 backend->requests.push_back(evt);
245 if (!backend->valid) {
246 luaL_error(L ,
"Error, you tried to use an invalid context object in a lua thread");
252 luaL_argerror(L, 1,
"Error, tried to parse a config but some fields were invalid");
270 for (std::size_t
i = 0;
i < queue.size(); ++
i) {
280 auto this_context_backend = std::make_shared<lua_context_backend>();
282 for (
const std::string & key : ctxt.
callbacks_ | boost::adaptors::map_keys ) {
293 for (
const plugins_context::accessor_list::value_type & v : ctxt.
accessors_) {
294 const std::string & key = v.first;
307 this_context_backend->valid =
false;
312 std::stringstream ss;
313 ss <<
"encountered a";
322 ss <<
" error-handler ";
329 ERR_LUA << ss.str() << std::endl;
LUA_API void lua_pushlightuserdata(lua_State *L, void *p)
#define lua_pushcfunction(L, f)
thread(const thread &)=delete
static void *const threadtableKey
void luaW_pushconfig(lua_State *L, const config &cfg)
Converts a config object to a Lua table pushed at the top of the stack.
LUA_API void lua_settop(lua_State *L, int idx)
LUA_API int lua_type(lua_State *L, int idx)
LUALIB_API int luaL_loadstring(lua_State *L, const char *s)
LUA_API void lua_rawseti(lua_State *L, int idx, lua_Integer n)
LUA_API int lua_gettop(lua_State *L)
LUA_API int lua_getglobal(lua_State *L, const char *name)
LUA_API void lua_settable(lua_State *L, int idx)
static int impl_context_backend(lua_State *L, std::shared_ptr< lua_context_backend > backend, std::string req_name)
LUA_API int lua_rawget(lua_State *L, int idx)
static int impl_context_accessor(lua_State *L, std::shared_ptr< lua_context_backend > backend, plugins_context::accessor_function func)
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
thread * load_script_from_string(const std::string &)
Definitions for the interface to Wesnoth Markup Language (WML).
void push_function(lua_State *L, const lua_function &f)
Pushes a std::function wrapper object onto the stack.
static lg::log_domain log_scripting_lua("scripting/lua")
LUALIB_API int luaL_argerror(lua_State *L, int arg, const char *extramsg)
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
static int intf_delay(lua_State *L)
std::string get_name(std::size_t idx)
std::vector< std::function< bool(void)> > request_list
static char * v_threadtableKey
std::vector< plugins_manager::event > requests
static lua_State * get_new_thread(lua_State *L)
bool protected_call(int nArgs, int nRets, error_handler)
LUA_API void lua_setglobal(lua_State *L, const char *name)
LUA_API int lua_status(lua_State *L)
LUA_API int lua_resume(lua_State *L, lua_State *from, int nargs, int *nresults)
bool luaW_toconfig(lua_State *L, int index, config &cfg)
Converts an optional table or vconfig to a config object.
LUALIB_API lua_Integer luaL_checkinteger(lua_State *L, int arg)
LUA_API void lua_rawset(lua_State *L, int idx)
config luaW_checkconfig(lua_State *L, int index)
Converts an optional table or vconfig to a config object.
#define lua_isfunction(L, n)
#define lua_tostring(L, i)
LUA_API void lua_pushvalue(lua_State *L, int idx)
int load_file(lua_State *L)
Loads a Lua file and pushes the contents on the stack.
std::function< config(config)> accessor_function
virtual void log_error(char const *msg, char const *context="Lua error")
Error reporting mechanisms, used by virtual methods protected_call and load_string.
#define lua_call(L, n, r)
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
std::string register_table(lua_State *L)
LUA_API lua_Unsigned lua_rawlen(lua_State *L, int idx)
#define LUA_REGISTRYINDEX
LUA_API int lua_error(lua_State *L)
#define lua_istable(L, n)
request_list run_script(const plugins_context &ctxt, const std::vector< plugins_manager::event > &queue)
Standard logging facilities (interface).
STATUS get_status(std::size_t idx)
LUA_API lua_State * lua_newthread(lua_State *L)
static int intf_describe_plugins(lua_State *L)
A config object defines a single node in a WML file, with access to child nodes.
LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
LUA_API const char * lua_pushstring(lua_State *L, const char *s)
LUA_API void lua_setfield(lua_State *L, int idx, const char *k)
thread * load_script_from_file(const std::string &)
LUA_API const char * lua_typename(lua_State *L, int t)
static plugins_manager * get()