mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-29 03:23:20 +00:00
Simplified function naming.
This commit is contained in:
parent
3e23887400
commit
ac99cc5f9d
@ -77,7 +77,7 @@ static bool to_map_location(lua_State *L, int &index, map_location &res)
|
||||
{
|
||||
if (lua_isuserdata(L, index))
|
||||
{
|
||||
unit const *u = lua::luaW_tounit(L, index);
|
||||
unit const *u = luaW_tounit(L, index);
|
||||
if (!u) return false;
|
||||
res = u->get_location();
|
||||
++index;
|
||||
@ -246,7 +246,7 @@ lua_ai_context* lua_ai_context::create(lua_State *L, char const *code, ai::engin
|
||||
}
|
||||
|
||||
//compile the ai as a closure
|
||||
if (!lua::luaW_pcall(L, 1, 1, true)) {
|
||||
if (!luaW_pcall(L, 1, 1, true)) {
|
||||
return NULL;//return with stack size 0 []
|
||||
}
|
||||
|
||||
@ -320,16 +320,16 @@ void lua_ai_action_handler::handle(config &cfg, bool configOut)
|
||||
if (!configOut)
|
||||
{
|
||||
lua_newtable(L);//stack size is 3 [-1: table -2: ai_context -3: ai_action]
|
||||
lua::table_of_wml_config(L, cfg);//the new table now contains the config
|
||||
lua::luaW_pcall(L, 2, LUA_MULTRET, true);
|
||||
luaW_pushconfig(L, cfg);//the new table now contains the config
|
||||
luaW_pcall(L, 2, LUA_MULTRET, true);
|
||||
}
|
||||
else if (lua_gettop(L) > initial_top)
|
||||
{
|
||||
if (lua::luaW_pcall(L, 1, LUA_MULTRET, true)) {
|
||||
if (luaW_pcall(L, 1, LUA_MULTRET, true)) {
|
||||
int score = lua_tonumber(L, initial_top + 1);//get score
|
||||
|
||||
if (lua_gettop(L) >= initial_top + 2) {//check if we also have config
|
||||
lua::luaW_toconfig(L, initial_top + 2, cfg);//get config
|
||||
luaW_toconfig(L, initial_top + 2, cfg);//get config
|
||||
}
|
||||
|
||||
cfg["score"] = score; // write score to the config
|
||||
|
@ -16,11 +16,7 @@
|
||||
#define AI_LUA_CORE_HPP
|
||||
|
||||
struct lua_State;
|
||||
|
||||
namespace lua {
|
||||
class LuaKernel;
|
||||
} // of namespace lua
|
||||
|
||||
class config;
|
||||
|
||||
namespace ai {
|
||||
@ -44,7 +40,7 @@ public:
|
||||
~lua_ai_context();
|
||||
void load();
|
||||
static void init(lua_State *L);
|
||||
friend class lua::LuaKernel;
|
||||
friend class ::LuaKernel;
|
||||
};
|
||||
|
||||
|
||||
@ -64,7 +60,7 @@ private:
|
||||
public:
|
||||
~lua_ai_action_handler();
|
||||
void handle(config &, bool configOut = false);
|
||||
friend class lua::LuaKernel;
|
||||
friend class ::LuaKernel;
|
||||
};
|
||||
|
||||
}//of namespace ai
|
||||
|
@ -1554,7 +1554,7 @@ void game_controller::load_game_cfg(const bool force)
|
||||
}
|
||||
|
||||
// Extract the Lua scripts at toplevel.
|
||||
lua::extract_preload_scripts(game_config_);
|
||||
extract_preload_scripts(game_config_);
|
||||
game_config_.clear_children("lua");
|
||||
|
||||
game_config_.merge_children("units");
|
||||
|
@ -3215,7 +3215,7 @@ namespace game_events {
|
||||
unit_wml_ids.insert(id);
|
||||
}
|
||||
|
||||
resources::lua_kernel = new lua::LuaKernel;
|
||||
resources::lua_kernel = new LuaKernel;
|
||||
manager_running = true;
|
||||
|
||||
foreach (static_wml_action_map::value_type &action, static_wml_actions) {
|
||||
|
@ -22,7 +22,7 @@ namespace resources
|
||||
unit_map *units;
|
||||
std::vector<team> *teams;
|
||||
game_state *state_of_game;
|
||||
lua::LuaKernel *lua_kernel;
|
||||
LuaKernel *lua_kernel;
|
||||
play_controller *controller;
|
||||
::tod_manager *tod_manager;
|
||||
wb::manager *whiteboard;
|
||||
|
@ -20,10 +20,7 @@
|
||||
class game_display;
|
||||
class gamemap;
|
||||
class game_state;
|
||||
namespace lua {
|
||||
class LuaKernel;
|
||||
} //of namespace lua
|
||||
|
||||
class LuaKernel;
|
||||
class play_controller;
|
||||
class team;
|
||||
class tod_manager;
|
||||
@ -43,7 +40,7 @@ namespace resources
|
||||
extern unit_map *units;
|
||||
extern std::vector<team> *teams;
|
||||
extern game_state *state_of_game;
|
||||
extern lua::LuaKernel *lua_kernel;
|
||||
extern LuaKernel *lua_kernel;
|
||||
extern play_controller *controller;
|
||||
extern tod_manager *tod_manager;
|
||||
extern wb::manager *whiteboard;
|
||||
|
@ -60,8 +60,6 @@ static lg::log_domain log_scripting_lua("scripting/lua");
|
||||
#define LOG_LUA LOG_STREAM(info, log_scripting_lua)
|
||||
#define ERR_LUA LOG_STREAM(err, log_scripting_lua)
|
||||
|
||||
namespace lua {
|
||||
|
||||
static std::vector<config> preload_scripts;
|
||||
|
||||
void extract_preload_scripts(config const &game_config)
|
||||
@ -223,7 +221,7 @@ static t_string luaW_checktstring(lua_State *L, int index)
|
||||
* The destination table should be at the top of the stack on entry. It is
|
||||
* still at the top on exit.
|
||||
*/
|
||||
void table_of_wml_config(lua_State *L, config const &cfg)
|
||||
void luaW_pushconfig(lua_State *L, config const &cfg)
|
||||
{
|
||||
if (!lua_checkstack(L, LUA_MINSTACK))
|
||||
return;
|
||||
@ -235,7 +233,7 @@ void table_of_wml_config(lua_State *L, config const &cfg)
|
||||
lua_pushstring(L, ch.key.c_str());
|
||||
lua_rawseti(L, -2, 1);
|
||||
lua_newtable(L);
|
||||
table_of_wml_config(L, ch.cfg);
|
||||
luaW_pushconfig(L, ch.cfg);
|
||||
lua_rawseti(L, -2, 2);
|
||||
lua_rawseti(L, -2, k++);
|
||||
}
|
||||
@ -617,12 +615,12 @@ static int impl_vconfig_get(lua_State *L)
|
||||
char const *m = luaL_checkstring(L, 2);
|
||||
if (strcmp(m, "__literal") == 0) {
|
||||
lua_newtable(L);
|
||||
table_of_wml_config(L, v->get_config());
|
||||
luaW_pushconfig(L, v->get_config());
|
||||
return 1;
|
||||
}
|
||||
if (strcmp(m, "__parsed") == 0) {
|
||||
lua_newtable(L);
|
||||
table_of_wml_config(L, v->get_parsed_config());
|
||||
luaW_pushconfig(L, v->get_parsed_config());
|
||||
return 1;
|
||||
}
|
||||
if (strcmp(m, "__shallow_literal") == 0) {
|
||||
@ -716,14 +714,14 @@ static int impl_vconfig_collect(lua_State *L)
|
||||
config cfg; \
|
||||
accessor; \
|
||||
lua_newtable(L); \
|
||||
table_of_wml_config(L, cfg); \
|
||||
luaW_pushconfig(L, cfg); \
|
||||
return 1; \
|
||||
}
|
||||
|
||||
#define return_cfgref_attrib(name, accessor) \
|
||||
if (strcmp(m, name) == 0) { \
|
||||
lua_newtable(L); \
|
||||
table_of_wml_config(L, accessor); \
|
||||
luaW_pushconfig(L, accessor); \
|
||||
return 1; \
|
||||
}
|
||||
|
||||
@ -1101,7 +1099,7 @@ static int intf_get_variable(lua_State *L)
|
||||
if (w.is_valid) {
|
||||
lua_newtable(L);
|
||||
if (lua_toboolean(L, 2))
|
||||
table_of_wml_config(L, w.as_container());
|
||||
luaW_pushconfig(L, w.as_container());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@ -1526,7 +1524,7 @@ static int impl_current_get(lua_State *L)
|
||||
cfg["y2"] = ev.loc2.y + 1;
|
||||
}
|
||||
lua_newtable(L);
|
||||
table_of_wml_config(L, cfg);
|
||||
luaW_pushconfig(L, cfg);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -2231,7 +2229,7 @@ static int intf_synchronize_choice(lua_State *L)
|
||||
lua_settop(L, 1);
|
||||
config cfg = mp_sync::get_user_choice("input", lua_synchronize(L));
|
||||
lua_newtable(L);
|
||||
table_of_wml_config(L, cfg);
|
||||
luaW_pushconfig(L, cfg);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -2984,6 +2982,3 @@ ai::lua_ai_action_handler* LuaKernel::create_lua_ai_action_handler(char const *c
|
||||
{
|
||||
return ai::lua_ai_action_handler::create(mState,code,context);
|
||||
}
|
||||
|
||||
} // of namespace lua
|
||||
|
||||
|
@ -25,8 +25,6 @@ class lua_ai_context;
|
||||
class engine_lua;
|
||||
} // of namespace ai
|
||||
|
||||
namespace lua {
|
||||
|
||||
void extract_preload_scripts(config const &);
|
||||
|
||||
class LuaKernel
|
||||
@ -48,6 +46,4 @@ public:
|
||||
void load_package();
|
||||
};
|
||||
|
||||
} //of namespace lua
|
||||
|
||||
#endif
|
||||
|
@ -15,19 +15,15 @@
|
||||
#ifndef SCRIPTING_LUA_API_HPP
|
||||
#define SCRIPTING_LUA_API_HPP
|
||||
|
||||
#include "game_events.hpp"
|
||||
#include <cstddef>
|
||||
|
||||
struct lua_State;
|
||||
|
||||
|
||||
namespace lua {
|
||||
class config;
|
||||
class unit;
|
||||
|
||||
bool luaW_pcall(lua_State *L , int nArgs, int nRets, bool allow_wml_error = false);
|
||||
|
||||
unit *luaW_tounit(lua_State *L, int index, bool only_on_map = false);
|
||||
|
||||
void table_of_wml_config(lua_State *L, config const &cfg);
|
||||
|
||||
void luaW_pushconfig(lua_State *L, config const &cfg);
|
||||
bool luaW_toconfig(lua_State *L, int index, config &cfg, int tstring_meta = 0);
|
||||
|
||||
/**
|
||||
@ -52,7 +48,4 @@ public:
|
||||
unit *get();
|
||||
};
|
||||
|
||||
|
||||
} //of namespace lua
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user