64 #define DBG_LUA LOG_STREAM(debug, log_scripting_lua)
65 #define LOG_LUA LOG_STREAM(info, log_scripting_lua)
66 #define WRN_LUA LOG_STREAM(warn, log_scripting_lua)
67 #define ERR_LUA LOG_STREAM(err, log_scripting_lua)
70 static const char *
Gen =
"name generator";
73 static const char *
Interp =
"lua interpreter";
82 template<VERSION_COMP_OP vop>
88 lua_pushboolean(L, result);
98 if(lua_isinteger(L, 2)) {
99 int n = lua_tointeger(L, 2) - 1;
101 if(
n >= 0 &&
size_t(
n) < components.size()) {
108 char const *m = luaL_checkstring(L, 2);
116 }
else if(strcmp(m,
"sep") == 0) {
125 static const std::vector<std::string> fields{
"major",
"minor",
"revision",
"is_canonical",
"special",
"sep"};
136 vers->~version_info();
156 if(luaL_testudata(L, 1,
Version)) {
162 if(lua_type(L, 1) == LUA_TSTRING) {
165 int major = luaL_checkinteger(L, 1), minor = luaL_optinteger(L, 2, 0), rev = luaL_optinteger(L, 3, 0);
166 std::string sep, special;
167 if(lua_type(L, -1) == LUA_TSTRING) {
168 special = lua_tostring(L, -1);
169 if(!special.empty() && std::isalpha(special[0])) {
172 sep.push_back(special[0]);
173 special = special.substr(1);
178 new(L)
version_info(major, minor, rev, sep[0], special);
180 if(luaL_newmetatable(L,
Version)) {
181 static const luaL_Reg metafuncs[] {
185 {
"__lt", &impl_version_compare<VERSION_COMP_OP::OP_LESS> },
186 {
"__le", &impl_version_compare<VERSION_COMP_OP::OP_LESS_OR_EQUAL> },
187 {
"__eq", &impl_version_compare<VERSION_COMP_OP::OP_EQUAL> },
191 luaL_setfuncs(L, metafuncs, 0);
192 luaW_table_set<std::string>(L, -1,
"__metatable",
Version);
194 lua_setmetatable(L, -2);
214 DBG_LUA <<
"intf_print called:";
215 std::size_t nargs = lua_gettop(L);
217 lua_getglobal(L,
"tostring");
218 for (std::size_t
i = 1;
i <= nargs; ++
i) {
219 lua_pushvalue(L, -1);
222 const char * str = lua_tostring(L, -1);
224 LOG_LUA <<
"'tostring' must return a value to 'print'";
243 static const char*
const prefix =
"Warning:\n ";
244 static std::ostringstream warning(prefix);
245 warning.seekp(0, std::ios::end);
246 warning <<
msg <<
' ';
248 auto L =
reinterpret_cast<lua_State*
>(
p);
251 lua_pushinteger(L, 2);
253 auto& lk = lua_kernel_base::get_lua_kernel<lua_kernel_base>(L);
254 lk.add_log_to_console(luaL_checkstring(L, -1));
270 std::string chunk = luaL_checkstring(L, 1);
271 const char* name = luaL_optstring(L, 2, chunk.c_str());
272 std::string mode = luaL_optstring(L, 3,
"t");
273 bool override_env = !lua_isnone(L, 4);
276 return luaL_argerror(L, 3,
"binary chunks are not allowed for security reasons");
279 int result = luaL_loadbufferx(L, chunk.data(), chunk.length(), name,
"t");
280 if(result != LUA_OK) {
292 const char* upvalue_name = lua_setupvalue(L, -2, 1);
293 if(upvalue_name ==
nullptr) {
307 lua_CFunction function = lua_tocfunction(L, lua_upvalueindex(1));
310 int nRets =
function(L);
322 std::string message =
"There is already an external logger attached to this lua kernel, you cannot open the lua console right now.";
334 lua_pushstring(L, gen->
generate().c_str());
347 std::string
type = luaL_checkstring(L, 1);
350 if(
type ==
"markov" ||
type ==
"markov_chain") {
351 std::vector<std::string> input;
352 if(lua_istable(L, 2)) {
353 input = lua_check<std::vector<std::string>>(L, 2);
357 int chain_sz = luaL_optinteger(L, 3, 2);
358 int max_len = luaL_optinteger(L, 4, 12);
362 }
else if(
type ==
"context_free" ||
type ==
"cfg" ||
type ==
"CFG") {
363 if(lua_istable(L, 2)) {
364 std::map<std::string, std::vector<std::string>>
data;
365 for(lua_pushnil(L); lua_next(L, 2); lua_pop(L, 1)) {
366 if(lua_type(L, -2) != LUA_TSTRING) {
367 lua_pushstring(L,
"CFG generator: invalid nonterminal name (must be a string)");
370 if(lua_isstring(L, -1)) {
372 if(productions.size() > 1) {
373 deprecated_message(
"wesnoth.name_generator('cfg', {nonterminal = 'a|b'})",
DEP_LEVEL::INDEFINITE,
"1.17",
"Non-terminals should now be assigned an array of productions instead of a single string containing productions separated by | - but a single string is fine if it's only one production");
375 }
else if(lua_istable(L, -1)) {
376 const auto&
split = lua_check<std::vector<t_string>>(L, -1);
377 auto& productions =
data[lua_tostring(L,-2)];
380 lua_pushstring(L,
"CFG generator: invalid nonterminal value (must be a string or list of strings)");
394 return luaL_argerror(L, 1,
"should be either 'markov_chain' or 'context_free'");
398 lua_pushstring(L, ex.
what());
404 luaL_getmetatable(L,
Gen);
405 lua_setmetatable(L, -2);
416 const std::string& logger = lua_isstring(L, 2) ? luaL_checkstring(L, 1) :
"";
417 std::string
msg = lua_isstring(L, 2) ? luaL_checkstring(L, 2) : luaL_checkstring(L, 1);
418 if(
msg.empty() ||
msg.back() !=
'\n') {
422 if(logger ==
"err" || logger ==
"error") {
424 }
else if(logger ==
"warn" || logger ==
"wrn" || logger ==
"warning") {
426 }
else if((logger ==
"debug" || logger ==
"dbg")) {
442 const std::string elem = luaL_checkstring(L, 1);
445 const std::string ver_str = lua_isnoneornil(L, 3) ?
"" : luaL_checkstring(L, 3);
454 lua_warning(L,
msg.c_str(),
false);
469 if(!lua_istable(L, 1)) {
472 auto names = lua_check<std::vector<std::string>>(L, 2);
474 int len = luaL_checkinteger(L, -1);
476 for(
int i = 1; i <= std::max<int>(len,
names.size());
i++) {
487 temp.
read(luaL_checkstring(L, 1));
488 std::set<map_location> locs;
489 for(
int x = 1; x <= temp.
width(); x++) {
490 for(
int y = 1; y <= temp.
height(); y++) {
491 if(!temp.
value(x, y)) {
505 for(
const auto& loc : locs) {
506 temp.
clear(loc.wml_x(), loc.wml_y());
517 lua_pushinteger(L, SDL_GetTicks());
529 switch(luaL_getmetafield(L, -1,
"__dir")) {
533 if(lua_pcall(L, 2, 1, 0) == LUA_OK) {
534 keys = lua_check<std::vector<std::string>>(L, -1);
536 lua_warning(L,
"wesnoth.print_attributes: __dir metamethod raised an error",
false);
540 auto dir_keys = lua_check<std::vector<std::string>>(L, -1);
541 std::copy(dir_keys.begin(), dir_keys.end(), std::back_inserter(keys));
550 auto key = luaL_checkstring(L, 2);
551 auto type = lua_getfield(L, 1, key);
552 if(
type == LUA_TTABLE) {
553 lua_pushliteral(L,
"__deprecated");
554 if(lua_rawget(L, -2) == LUA_TBOOLEAN) {
556 lua_pushboolean(L, deprecated);
561 lua_pushboolean(L,
false);
568 auto key = luaL_checkstring(L, 2);
569 std::string suffix =
" ";
570 auto type = lua_getfield(L, 1, key);
571 if(
type == LUA_TTABLE) {
573 }
else if(
type == LUA_TFUNCTION) {
575 }
else if(
type == LUA_TUSERDATA) {
576 lua_getglobal(L,
"getmetatable");
577 lua_pushvalue(L, -2);
579 if(lua_type(L, -1) == LUA_TSTRING) {
580 auto meta = lua_check<std::string>(L, -1);
581 if(meta ==
"function") {
586 suffix =
" " + suffix;
587 lua_pushlstring(L, suffix.c_str(), suffix.size());
597 if(idx < 0 && idx >= -lua_gettop(L)) {
598 idx = lua_absindex(L, idx);
600 std::vector<std::string> keys;
601 if(lua_istable(L, idx)) {
604 int save_top = lua_gettop(L);
605 lua_pushvalue(L, idx);
607 lua_settop(L, save_top);
610 int table_idx = lua_absindex(L, -1);
611 for(lua_pushnil(L); lua_next(L, table_idx); lua_pop(L, 1)) {
612 if(lua_type(L, -2) == LUA_TSTRING) {
613 keys.push_back(lua_tostring(L,-2));
621 if(luaL_getmetafield(L, table_idx,
"__index") == LUA_TNIL)
break;
622 }
while(lua_istable(L, -1));
623 if(lua_isfunction(L, -1)) {
627 }
else if(lua_isuserdata(L, idx) && !lua_islightuserdata(L, idx)) {
628 lua_pushvalue(L, idx);
633 std::sort(keys.begin(), keys.end());
634 auto new_end = std::unique(keys.begin(), keys.end());
635 new_end = std::remove_if(keys.begin(), new_end, [L, idx](
const std::string& key) {
636 if(key.compare(0, 2,
"__") == 0) {
639 int save_top = lua_gettop(L);
641 lua_settop(L, save_top);
648 lua_pushvalue(L, idx);
650 if(lua_pcall(L, 2, 1, 0) == LUA_OK) {
655 keys.erase(new_end, keys.end());
673 if(lua_isnil(L, 1))
return luaL_argerror(L, 1,
"Can't dir() nil");
674 if(!lua_isfunction(L, 2)) {
677 int fcn_idx = lua_gettop(L);
679 size_t max_len = std::accumulate(keys.begin(), keys.end(), 0, [](
size_t max,
const std::string& next) {
680 return std::max(max, next.size());
683 static const size_t MAX_WIDTH = 80, COL_PADDING = 3, SUFFIX_PADDING = 2;
684 size_t col_width = max_len + COL_PADDING + SUFFIX_PADDING;
685 size_t n_cols = (MAX_WIDTH + COL_PADDING) / col_width;
686 size_t n_rows = ceil(keys.size() /
double(n_cols));
687 for(
size_t i = 0;
i < n_rows;
i++) {
688 std::ostringstream
line;
690 line.setf(std::ios::left);
691 for(
size_t j = 0; j < n_cols && j + (
i * n_cols) < keys.size(); j++) {
692 int save_top = lua_gettop(L);
694 lua_settop(L, save_top);
698 const auto& key = keys[j +
i * n_cols];
699 lua_pushlstring(L, key.c_str(), key.size());
700 std::string suffix =
" !";
701 if(lua_pcall(L, 2, 1, 0) == LUA_OK) {
702 suffix = luaL_checkstring(L, -1);
706 line.width(col_width - SUFFIX_PADDING + suffix.size());
710 lua_pushvalue(L, fcn_idx);
722 template <member_callback method>
724 return ((lua_kernel_base::get_lua_kernel<lua_kernel_base>(L)).*method)(L);
729 : mState(luaL_newstate())
739 cmd_log_ <<
"Adding boost function proxy...\n";
745 cmd_log_ <<
"Adding standard libs...\n";
747 static const luaL_Reg safe_libs[] {
748 {
"", luaopen_base },
749 {
"table", luaopen_table },
750 {
"string", luaopen_string },
751 {
"math", luaopen_math },
752 {
"coroutine", luaopen_coroutine },
753 {
"debug", luaopen_debug },
754 {
"os", luaopen_os },
755 {
"utf8", luaopen_utf8 },
764 for (luaL_Reg
const *lib = safe_libs; lib->func; ++lib)
766 luaL_requiref(L, lib->name, lib->func, strlen(lib->name));
771 lua_getglobal(L,
"os");
773 while(lua_next(L, -2) != 0) {
775 char const*
function = lua_tostring(L, -1);
776 if(strcmp(
function,
"clock") == 0 || strcmp(
function,
"date") == 0
777 || strcmp(
function,
"time") == 0 || strcmp(
function,
"difftime") == 0)
continue;
779 lua_setfield(L, -3,
function);
785 lua_setglobal(L,
"dofile");
787 lua_setglobal(L,
"loadfile");
790 cmd_log_ <<
"Adding error handler...\n";
797 cmd_log_ <<
"Registering basic wesnoth API...\n";
799 static luaL_Reg
const callbacks[] {
802 {
"dofile", &dispatch<&lua_kernel_base::intf_dofile> },
803 {
"require", &dispatch<&lua_kernel_base::intf_require> },
804 {
"kernel_type", &dispatch<&lua_kernel_base::intf_kernel_type> },
818 lua_getglobal(L,
"wesnoth");
819 if (!lua_istable(L,-1)) {
822 luaL_setfuncs(L, callbacks, 0);
824 lua_setglobal(L,
"wesnoth");
834 cmd_log_ <<
"Redirecting print function...\n";
836 lua_getglobal(L,
"print");
837 lua_setglobal(L,
"std_print");
841 lua_pushcfunction(L, &dispatch<&lua_kernel_base::intf_print>);
842 lua_setglobal(L,
"print");
845 lua_setglobal(L,
"load");
847 lua_setglobal(L,
"loadstring");
850 cmd_log_ <<
"Wrapping pcall and xpcall functions...\n";
851 lua_getglobal(L,
"pcall");
853 lua_setglobal(L,
"pcall");
854 lua_getglobal(L,
"xpcall");
856 lua_setglobal(L,
"xpcall");
858 cmd_log_ <<
"Initializing package repository...\n";
860 lua_getglobal(L,
"wesnoth");
862 lua_setfield(L, -2,
"package");
865 lua_pushstring(L,
"lua/package.lua");
868 cmd_log_ <<
"Error: Failed to initialize package repository. Falling back to less flexible C++ implementation.\n";
872 cmd_log_ <<
"Adding map table...\n";
874 static luaL_Reg
const map_callbacks[] {
893 lua_getglobal(L,
"wesnoth");
895 luaL_setfuncs(L, map_callbacks, 0);
896 lua_setfield(L, -2,
"map");
900 cmd_log_ <<
"Adding game_config table...\n";
902 lua_getglobal(L,
"wesnoth");
903 lua_newuserdatauv(L, 0, 0);
904 lua_createtable(L, 0, 3);
905 lua_pushcfunction(L, &dispatch<&lua_kernel_base::impl_game_config_get>);
906 lua_setfield(L, -2,
"__index");
907 lua_pushcfunction(L, &dispatch<&lua_kernel_base::impl_game_config_set>);
908 lua_setfield(L, -2,
"__newindex");
909 lua_pushstring(L,
"game config");
910 lua_setfield(L, -2,
"__metatable");
911 lua_setmetatable(L, -2);
912 lua_setfield(L, -2,
"game_config");
916 cmd_log_ <<
"Adding rng tables...\n";
919 cmd_log_ <<
"Adding name generator metatable...\n";
920 luaL_newmetatable(L,
Gen);
934 cmd_log_ <<
"Sandboxing Lua interpreter...\nTo make variables visible outside the interpreter, assign to _G.variable.\n";
935 cmd_log_ <<
"The special variable _ holds the result of the last expression (if any).\n";
937 lua_createtable(L, 0, 1);
938 lua_getglobal(L,
"_G");
939 lua_setfield(L, -2,
"__index");
940 lua_setmetatable(L, -2);
942 lua_setfield(L, -2,
"dir");
943 lua_setfield(L, LUA_REGISTRYINDEX,
Interp);
950 lua_pushstring(L,
"lua/ilua.lua");
953 lua_pushstring(L,
"set_strict");
956 cmd_log_ <<
"Failed to activate strict mode.\n";
958 cmd_log_ <<
"Activated strict mode.\n";
961 lua_setglobal(L,
"ilua");
963 cmd_log_ <<
"Error: failed to load ilua.\n";
969 lua_getglobal(L,
"debug");
971 while(lua_next(L, -2) != 0) {
973 char const*
function = lua_tostring(L, -1);
974 if(strcmp(
function,
"traceback") == 0 || strcmp(
function,
"getinfo") == 0)
continue;
976 lua_setfield(L, -3,
function);
1020 if (errcode != LUA_OK) {
1021 char const *
msg = lua_tostring(L, -1);
1023 std::string context =
"When executing, ";
1024 if (errcode == LUA_ERRRUN) {
1025 context +=
"Lua runtime error: ";
1026 }
else if (errcode == LUA_ERRERR) {
1027 context +=
"Lua error in attached debugger: ";
1028 }
else if (errcode == LUA_ERRMEM) {
1029 context +=
"Lua out of memory error: ";
1031 context +=
"unknown lua error: ";
1033 if(lua_isstring(L, -1)) {
1034 context +=
msg ?
msg :
"null string";
1036 context += lua_typename(L, lua_type(L, -1));
1041 e_h(context.c_str(),
"Lua Error");
1052 int errcode = luaL_loadbufferx(
mState, prog, strlen(prog), name.empty() ? prog : name.c_str(),
"t");
1053 if (errcode != LUA_OK) {
1054 char const *
msg = lua_tostring(
mState, -1);
1055 std::string message =
msg ?
msg :
"null string";
1057 std::string context =
"When parsing a string to lua, ";
1059 if (errcode == LUA_ERRSYNTAX) {
1060 context +=
" a syntax error";
1061 }
else if(errcode == LUA_ERRMEM){
1062 context +=
" a memory error";
1064 context +=
" an unknown error";
1069 e_h(message.c_str(), context.c_str());
1083 this->
run(cfg[
"code"].str().c_str(), cfg[
"name"].str(), nArgs);
1092 if(in_interpreter) {
1094 if(lua_setupvalue(
mState, -2, 1) ==
nullptr)
1097 lua_insert(
mState, -nArgs - 1);
1098 this->
protected_call(nArgs, in_interpreter ? LUA_MULTRET : 0, eh);
1114 std::string experiment =
"return ";
1116 int top = lua_gettop(
mState);
1123 this->
load_string(experiment.c_str(),
"interactive", eh);
1125 if(lua_setupvalue(
mState, -2, 1) ==
nullptr)
1129 if(lua_gettop(
mState) == top + 1) {
1139 int nRets = lua_gettop(
mState) - top - 1;
1143 int env_idx = lua_gettop(
mState);
1144 lua_pushvalue(
mState, top + 2);
1145 lua_setfield(
mState, -2,
"_");
1148 for(
int i = top + 2;
i < env_idx;
i++)
1151 lua_setfield(
mState, -2,
"_all");
1164 luaL_checkstring(L, 1);
1165 lua_rotate(L, 1, -1);
1168 lua_rotate(L, 1, 1);
1172 lua_call(L, lua_gettop(L) - 1, LUA_MULTRET);
1173 return lua_gettop(L);
1184 const char * m = luaL_checkstring(L, 1);
1186 return luaL_argerror(L, 1,
"found a null string argument to wesnoth require");
1191 lua_getglobal(L,
"wesnoth");
1192 lua_pushstring(L,
"package");
1194 lua_pushvalue(L, 1);
1200 lua_pushvalue(L, 1);
1208 DBG_LUA <<
"require: loaded a file, now calling it";
1216 lua_pushvalue(L, 1);
1217 lua_pushvalue(L, -2);
1221 lua_settable(L, -4);
1232 char const *m = luaL_checkstring(L, 2);
1250 std::string err_msg =
"unknown modifiable property of game_config: ";
1251 err_msg += luaL_checkstring(L, 2);
1252 return luaL_argerror(L, 2, err_msg.c_str());
1263 lua_pushcfunction(L, luaopen_package);
1264 lua_pushstring(L,
"package");
1274 lua_pushstring(L,
"lua/core");
1276 cmd_log_ <<
"Error: Failed to load core.\n";
1286 std::vector<std::string> ret;
1290 int idx = lua_gettop(L);
1291 lua_getglobal(L,
"_G");
1294 while (lua_next(L, idx+1) != 0) {
1295 if (lua_isstring(L, -2)) {
1296 ret.push_back(lua_tostring(L,-2));
1309 std::vector<std::string> ret;
1310 std::string base_path = input;
1311 std::size_t last_dot = base_path.find_last_of(
'.');
1312 std::string partial_name = base_path.substr(last_dot + 1);
1313 base_path.erase(last_dot);
1314 std::string
load =
"return " + base_path;
1317 int save_stack = lua_gettop(L);
1318 int result = luaL_loadstring(L,
load.c_str());
1319 if(result != LUA_OK) {
1321 LOG_LUA <<
"Error when attempting tab completion:";
1322 LOG_LUA << luaL_checkstring(L, -1);
1324 lua_settop(L, save_stack);
1329 if(lua_istable(L, -1) || lua_isuserdata(L, -1)) {
1330 int top = lua_gettop(L);
1331 int obj = lua_absindex(L, -1);
1332 if(luaL_getmetafield(L, obj,
"__tab_enum") == LUA_TFUNCTION) {
1333 lua_pushvalue(L, obj);
1334 lua_pushlstring(L, partial_name.c_str(), partial_name.size());
1336 ret = lua_check<std::vector<std::string>>(L, -1);
1337 }
else if(lua_type(L, -1) != LUA_TTABLE) {
1338 LOG_LUA <<
"Userdata missing __tab_enum meta-function for tab completion";
1339 lua_settop(L, save_stack);
1344 for(lua_pushnil(L); lua_next(L, obj); lua_pop(L, 1)) {
1345 if(lua_type(L, -2) == LUA_TSTRING) {
1346 std::string attr = lua_tostring(L, -2);
1350 if(!isalpha(attr[0]) && attr[0] !=
'_') {
1353 if(std::any_of(attr.begin(), attr.end(), [](
char c){
1354 return !isalpha(c) && !isdigit(c) && c !=
'_';
1358 if(attr.substr(0, partial_name.size()) == partial_name) {
1359 ret.push_back(base_path +
"." + attr);
1365 lua_settop(L, save_stack);
1372 #pragma GCC diagnostic push
1373 #pragma GCC diagnostic ignored "-Wold-style-cast"
1377 #pragma GCC diagnostic pop
std::vector< std::string > names
A config object defines a single node in a WML file, with access to child nodes.
optional_config_impl< config > optional_child(config_key_type key, int n=0)
Euivalent to mandatory_child, but returns an empty optional if the nth child was not found.
static void rethrow()
Rethrows the stored exception.
void load_core()
Loads the "core" library into the Lua environment.
void run(char const *prog, const std::string &name, int nArgs=0)
Runs a plain script.
virtual void log_error(char const *msg, char const *context="Lua error")
Error reporting mechanisms, used by virtual methods protected_call and load_string.
int intf_dofile(lua_State *L)
Loads and executes a Lua file.
virtual int impl_game_config_get(lua_State *L)
int intf_require(lua_State *L)
Loads and executes a Lua file, if there is no corresponding entry in wesnoth.package.
void throwing_run(char const *prog, const std::string &name, int nArgs, bool in_interpreter=false)
Runs a plain script, but reports errors by throwing lua_error.
int intf_kernel_type(lua_State *L)
virtual int impl_game_config_set(lua_State *L)
void load_package()
Loads the package library into lua environment.
bool protected_call(int nArgs, int nRets, error_handler)
void add_log_to_console(const std::string &msg)
int intf_show_lua_console(lua_State *L)
bool load_string(char const *prog, const std::string &name, error_handler)
std::vector< std::tuple< std::string, std::string > > registered_widget_definitions_
static lua_kernel_base *& get_lua_kernel_base_ptr(lua_State *L)
std::vector< std::string > get_global_var_names()
Get tab completion strings.
std::function< void(char const *, char const *)> error_handler
void run_lua_tag(const config &cfg)
Runs a [lua] tag.
virtual ~lua_kernel_base()
int intf_print(lua_State *L)
Replacement print function – instead of printing to std::cout, print to the command log.
void interactive_run(char const *prog)
Tests if a program resolves to an expression, and pretty prints it if it is, otherwise it runs it nor...
std::vector< std::string > get_attribute_names(const std::string &var_path)
Gets all attribute names of an extended variable name.
virtual uint32_t get_random_seed()
virtual void throw_exception(char const *msg, char const *context="Lua error")
virtual std::string my_name()
User-visible name of the lua kernel that they are talking to.
const char * what() const noexcept
std::string generate(const std::map< std::string, std::string > &variables) const
virtual ~name_generator()
void read(const std::string &shroud_data)
void set_enabled(bool enabled)
bool value(int x, int y) const
std::string write() const
const std::string & str() const
Represents version numbers.
std::string str() const
Serializes the version number into string form.
unsigned int revision_level() const
Retrieves the revision level (x3 in "x1.x2.x3").
char special_version_separator() const
Retrieves the special version separator (e.g.
const std::string & special_version() const
Retrieves the special version suffix (e.g.
unsigned int minor_version() const
Retrieves the minor version number (x2 in "x1.x2.x3").
unsigned int major_version() const
Retrieves the major version number (x1 in "x1.x2.x3").
const std::vector< unsigned int > & components() const
Read-only access to all numeric components.
bool is_canonical() const
Whether the version number is considered canonical for mainline Wesnoth.
std::string deprecated_message(const std::string &elem_name, DEP_LEVEL level, const version_info &version, const std::string &detail)
DEP_LEVEL
See https://wiki.wesnoth.org/CompatibilityStandards for more info.
int(* lua_CFunction)(lua_State *L)
bool do_version_check(const version_info &a, VERSION_COMP_OP op, const version_info &b)
Interfaces for manipulating version numbers of engine, add-ons, etc.
const language_def & get_language()
Standard logging facilities (interface).
#define LOG_STREAM(level, domain)
void luaW_pushconfig(lua_State *L, const config &cfg)
Converts a config object to a Lua table pushed at the top of the stack.
int luaW_pcall_internal(lua_State *L, int nArgs, int nRets)
void push_error_handler(lua_State *L)
void luaW_push_namedtuple(lua_State *L, const std::vector< std::string > &names)
Push an empty "named tuple" onto the stack.
std::set< map_location > luaW_check_locationset(lua_State *L, int idx)
Converts a table of integer pairs to a set of map location objects.
bool luaW_toboolean(lua_State *L, int n)
int luaW_type_error(lua_State *L, int narg, const char *tname)
bool luaW_pcall(lua_State *L, int nArgs, int nRets, bool allow_wml_error)
Calls a Lua function stored below its nArgs arguments at the top of the stack.
int luaW_push_locationset(lua_State *L, const std::set< map_location > &locs)
Converts a set of map locations to a Lua table pushed at the top of the stack.
bool luaW_getglobal(lua_State *L, const std::vector< std::string > &path)
Pushes the value found by following the variadic names (char *), if the value is not nil.
t_string luaW_checktstring(lua_State *L, int index)
Converts a scalar to a translatable string.
#define return_string_attrib(name, accessor)
#define return_int_attrib(name, accessor)
#define return_bool_attrib(name, accessor)
#define return_string_attrib_deprecated(name, prefix, level, version, msg, accessor)
static int intf_make_shroud_bitmap(lua_State *L)
static int impl_version_finalize(lua_State *L)
Destroy a version.
int dispatch(lua_State *L)
static int intf_name_generator(lua_State *L)
static lg::log_domain log_user("scripting/lua/user")
static int intf_current_version(lua_State *L)
Returns the current Wesnoth version.
static lg::log_domain log_scripting_lua("scripting/lua")
static int intf_parse_shroud_bitmap(lua_State *L)
static int intf_make_version(lua_State *L)
Builds a version from its component parts, or parses it from a string.
static int impl_version_dir(lua_State *L)
static int impl_version_get(lua_State *L)
Decomposes a version into its component parts.
static int impl_get_dir_suffix(lua_State *L)
static int impl_version_tostring(lua_State *L)
Convert a version to string form.
static int intf_deprecated_message(lua_State *L)
Logs a deprecation message.
static int intf_pcall(lua_State *L)
Wrapper for pcall and xpcall functions to rethrow jailbreak exceptions.
static int intf_named_tuple(lua_State *L)
Converts a Lua array to a named tuple.
static void impl_warn(void *p, const char *msg, int tocont)
int(lua_kernel_base::* member_callback)(lua_State *L)
static const char * Version
static int intf_log(lua_State *L)
Logs a message Arg 1: (optional) Logger Arg 2: Message.
static int impl_is_deprecated(lua_State *L)
static const char * Interp
std::vector< std::string > luaW_get_attributes(lua_State *L, int idx)
This function does the actual work of grabbing all the attribute names.
static int intf_load(lua_State *L)
Replacement load function.
static int intf_ms_since_init(lua_State *L)
Returns the time stamp, exactly as [set_variable] time=stamp does.
static int intf_get_language(lua_State *L)
static int impl_name_generator_call(lua_State *L)
static void dir_meta_helper(lua_State *L, std::vector< std::string > &keys)
static int intf_object_dir(lua_State *L)
Prints out a list of keys available in an object.
static int impl_name_generator_collect(lua_State *L)
static int impl_version_compare(lua_State *L)
Compares two versions.
void line(int from_x, int from_y, int to_x, int to_y)
Draw a line.
const version_info wesnoth_version(VERSION)
std::vector< game_tip > load(const config &cfg)
Loads the tips from a config.
void remove_single_widget_definition(const std::string &widget_type, const std::string &definition_id)
Removes a widget definition from the default GUI.
std::string register_metatables(lua_State *L)
int intf_textdomain(lua_State *L)
Creates an interface for gettext.
std::string register_gettext_metatable(lua_State *L)
Adds the gettext metatable.
std::string register_tstring_metatable(lua_State *L)
Adds the tstring metatable.
void register_metatable(lua_State *L)
int luaW_open(lua_State *L)
int load_file(lua_State *L)
Loads a Lua file and pushes the contents on the stack.
int luaW_open(lua_State *L)
int show_lua_console(lua_State *, lua_kernel_base *lk)
int intf_get_relative_dir(lua_State *L)
Expose map_location get_relative_dir.
int intf_vector_negation(lua_State *L)
Expose map_location::vector_negation to lua.
int intf_distance_between(lua_State *L)
Expose map_location distance_between.
int intf_get_in_basis_N_NE(lua_State *L)
Expose map_location get_in_basis_N_NE.
int intf_tiles_adjacent(lua_State *L)
Expose map_location tiles_adjacent.
int intf_vector_diff(lua_State *L)
Expose map_location::vector_difference to lua.
int intf_vector_sum(lua_State *L)
Expose map_location::vector_sum to lua.
int intf_rotate_right_around_center(lua_State *L)
Expose map_location::rotate_right_around_center to lua.
int intf_get_tiles_in_radius(lua_State *L)
Expose map_location get_tiles_in_radius.
int intf_get_adjacent_tiles(lua_State *L)
Expose map_location get_adjacent_tiles.
int intf_get_direction(lua_State *L)
Expose map_location::get_direction function to lua Arg 1: a location Arg 2: a direction Arg 3: (optio...
int luaW_open(lua_State *L)
void load_tables(lua_State *L)
Creates the metatable for RNG objects, and adds the Rng table which contains the constructor.
int luaW_open(lua_State *L)
int luaW_open(lua_State *L)
rng * generator
This generator is automatically synced during synced context.
std::vector< std::string > parenthetical_split(std::string_view val, const char separator, std::string_view left, std::string_view right, const int flags)
Splits a string based either on a separator, except then the text appears within specified parenthesi...
std::vector< std::string > split(const config_attribute_value &val)
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
void lua_push(lua_State *L, const T &val)
static std::string flush(std::ostringstream &s)
#define ON_SCOPE_EXIT(...)
Run some arbitrary code (a lambda) when the current scope exits The lambda body follows this header,...
Error used to report an error in a lua script or in the lua interpreter.
external_log_type external_log_
static map_location::DIRECTION n