52 #include <boost/make_shared.hpp>
53 #include <boost/noncopyable.hpp>
54 #include <boost/range/adaptors.hpp>
55 #include <boost/shared_ptr.hpp>
65 #define DBG_LUA LOG_STREAM(debug, log_scripting_lua)
66 #define LOG_LUA LOG_STREAM(info, log_scripting_lua)
67 #define WRN_LUA LOG_STREAM(warn, log_scripting_lua)
68 #define ERR_LUA LOG_STREAM(err, log_scripting_lua)
77 std::stringstream line;
111 return "not started";
162 DBG_LUA <<
"loading script from string:\n<<\n" << prog <<
"\n>>\n";
169 std::string context =
"When parsing a string to a lua thread, ";
172 context +=
" a syntax error";
174 context +=
" a memory error";
176 context +=
" an error in garbage collection metamethod";
178 context +=
" an unknown error";
184 throw game::lua_error(
"Error when executing a script to make a lua thread.");
201 throw game::lua_error(
"Error when executing a file to make a lua thread.");
222 if (!backend->valid) {
223 luaL_error(L ,
"Error, you tried to use an invalid context object in a lua thread");
230 backend->requests.push_back(evt);
236 if (!backend->valid) {
237 luaL_error(L ,
"Error, you tried to use an invalid context object in a lua thread");
243 luaL_argerror(L, 1,
"Error, tried to parse a config but some fields were invalid");
261 for (
size_t i = 0;
i < queue.size(); ++
i) {
284 for (
const plugins_context::accessor_list::value_type &
v : ctxt.
accessors_) {
297 this_context_backend->valid =
false;
302 std::stringstream ss;
303 ss <<
"encountered a";
312 ss <<
" error-handler ";
319 ERR_LUA << ss.str() << std::endl;
LUA_API void lua_pushlightuserdata(lua_State *L, void *p)
#define lua_pushcfunction(L, f)
static void *const threadtableKey
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_getglobal(lua_State *L, const char *var)
LUA_API int lua_gettop(lua_State *L)
LUA_API void lua_settable(lua_State *L, int idx)
STATUS get_status(size_t idx)
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
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")
LUA_API void lua_setglobal(lua_State *L, const char *var)
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 int lua_status(lua_State *L)
bool luaW_toconfig(lua_State *L, int index, config &cfg)
Converts an optional table or vconfig to a config object.
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)
application_lua_kernel(CVideo *)
LUALIB_API int luaL_argerror(lua_State *L, int narg, const char *extramsg)
#define lua_tostring(L, i)
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
LUA_API void lua_rawseti(lua_State *L, int idx, int n)
static int impl_context_backend(lua_State *L, boost::shared_ptr< lua_context_backend > backend, std::string req_name)
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
LUA_API int lua_resume(lua_State *L, lua_State *from, int nargs)
virtual void log_error(char const *msg, char const *context="Lua error")
#define lua_call(L, n, r)
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
std::string get_name(size_t idx)
GLuint const GLchar * name
#define LUA_REGISTRYINDEX
LUA_API int lua_error(lua_State *L)
#define lua_istable(L, n)
void luaW_pushconfig(lua_State *L, config const &cfg)
Converts a config object to a Lua table pushed at the top of the stack.
request_list run_script(const plugins_context &ctxt, const std::vector< plugins_manager::event > &queue)
Standard logging facilities (interface).
static int impl_context_accessor(lua_State *L, boost::shared_ptr< lua_context_backend > backend, plugins_context::accessor_function func)
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 void lua_rawget(lua_State *L, int idx)
GLsizei const GLcharARB ** string
LUA_API const char * lua_pushstring(lua_State *L, const char *s)
thread * load_script_from_file(const std::string &)
LUA_API const char * lua_typename(lua_State *L, int t)
static plugins_manager * get()