Simplified function naming.

This commit is contained in:
Guillaume Melquiond 2010-08-06 16:30:57 +00:00
parent 3e23887400
commit ac99cc5f9d
9 changed files with 26 additions and 49 deletions

View File

@ -77,7 +77,7 @@ static bool to_map_location(lua_State *L, int &index, map_location &res)
{ {
if (lua_isuserdata(L, index)) if (lua_isuserdata(L, index))
{ {
unit const *u = lua::luaW_tounit(L, index); unit const *u = luaW_tounit(L, index);
if (!u) return false; if (!u) return false;
res = u->get_location(); res = u->get_location();
++index; ++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 //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 [] return NULL;//return with stack size 0 []
} }
@ -320,16 +320,16 @@ void lua_ai_action_handler::handle(config &cfg, bool configOut)
if (!configOut) if (!configOut)
{ {
lua_newtable(L);//stack size is 3 [-1: table -2: ai_context -3: ai_action] 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 luaW_pushconfig(L, cfg);//the new table now contains the config
lua::luaW_pcall(L, 2, LUA_MULTRET, true); luaW_pcall(L, 2, LUA_MULTRET, true);
} }
else if (lua_gettop(L) > initial_top) 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 int score = lua_tonumber(L, initial_top + 1);//get score
if (lua_gettop(L) >= initial_top + 2) {//check if we also have config 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 cfg["score"] = score; // write score to the config

View File

@ -16,11 +16,7 @@
#define AI_LUA_CORE_HPP #define AI_LUA_CORE_HPP
struct lua_State; struct lua_State;
namespace lua {
class LuaKernel; class LuaKernel;
} // of namespace lua
class config; class config;
namespace ai { namespace ai {
@ -44,7 +40,7 @@ public:
~lua_ai_context(); ~lua_ai_context();
void load(); void load();
static void init(lua_State *L); static void init(lua_State *L);
friend class lua::LuaKernel; friend class ::LuaKernel;
}; };
@ -64,7 +60,7 @@ private:
public: public:
~lua_ai_action_handler(); ~lua_ai_action_handler();
void handle(config &, bool configOut = false); void handle(config &, bool configOut = false);
friend class lua::LuaKernel; friend class ::LuaKernel;
}; };
}//of namespace ai }//of namespace ai

View File

@ -1554,7 +1554,7 @@ void game_controller::load_game_cfg(const bool force)
} }
// Extract the Lua scripts at toplevel. // Extract the Lua scripts at toplevel.
lua::extract_preload_scripts(game_config_); extract_preload_scripts(game_config_);
game_config_.clear_children("lua"); game_config_.clear_children("lua");
game_config_.merge_children("units"); game_config_.merge_children("units");

View File

@ -3215,7 +3215,7 @@ namespace game_events {
unit_wml_ids.insert(id); unit_wml_ids.insert(id);
} }
resources::lua_kernel = new lua::LuaKernel; resources::lua_kernel = new LuaKernel;
manager_running = true; manager_running = true;
foreach (static_wml_action_map::value_type &action, static_wml_actions) { foreach (static_wml_action_map::value_type &action, static_wml_actions) {

View File

@ -22,7 +22,7 @@ namespace resources
unit_map *units; unit_map *units;
std::vector<team> *teams; std::vector<team> *teams;
game_state *state_of_game; game_state *state_of_game;
lua::LuaKernel *lua_kernel; LuaKernel *lua_kernel;
play_controller *controller; play_controller *controller;
::tod_manager *tod_manager; ::tod_manager *tod_manager;
wb::manager *whiteboard; wb::manager *whiteboard;

View File

@ -20,10 +20,7 @@
class game_display; class game_display;
class gamemap; class gamemap;
class game_state; class game_state;
namespace lua { class LuaKernel;
class LuaKernel;
} //of namespace lua
class play_controller; class play_controller;
class team; class team;
class tod_manager; class tod_manager;
@ -43,7 +40,7 @@ namespace resources
extern unit_map *units; extern unit_map *units;
extern std::vector<team> *teams; extern std::vector<team> *teams;
extern game_state *state_of_game; extern game_state *state_of_game;
extern lua::LuaKernel *lua_kernel; extern LuaKernel *lua_kernel;
extern play_controller *controller; extern play_controller *controller;
extern tod_manager *tod_manager; extern tod_manager *tod_manager;
extern wb::manager *whiteboard; extern wb::manager *whiteboard;

View File

@ -60,8 +60,6 @@ static lg::log_domain log_scripting_lua("scripting/lua");
#define LOG_LUA LOG_STREAM(info, log_scripting_lua) #define LOG_LUA LOG_STREAM(info, log_scripting_lua)
#define ERR_LUA LOG_STREAM(err, log_scripting_lua) #define ERR_LUA LOG_STREAM(err, log_scripting_lua)
namespace lua {
static std::vector<config> preload_scripts; static std::vector<config> preload_scripts;
void extract_preload_scripts(config const &game_config) 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 * The destination table should be at the top of the stack on entry. It is
* still at the top on exit. * 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)) if (!lua_checkstack(L, LUA_MINSTACK))
return; return;
@ -235,7 +233,7 @@ void table_of_wml_config(lua_State *L, config const &cfg)
lua_pushstring(L, ch.key.c_str()); lua_pushstring(L, ch.key.c_str());
lua_rawseti(L, -2, 1); lua_rawseti(L, -2, 1);
lua_newtable(L); lua_newtable(L);
table_of_wml_config(L, ch.cfg); luaW_pushconfig(L, ch.cfg);
lua_rawseti(L, -2, 2); lua_rawseti(L, -2, 2);
lua_rawseti(L, -2, k++); lua_rawseti(L, -2, k++);
} }
@ -617,12 +615,12 @@ static int impl_vconfig_get(lua_State *L)
char const *m = luaL_checkstring(L, 2); char const *m = luaL_checkstring(L, 2);
if (strcmp(m, "__literal") == 0) { if (strcmp(m, "__literal") == 0) {
lua_newtable(L); lua_newtable(L);
table_of_wml_config(L, v->get_config()); luaW_pushconfig(L, v->get_config());
return 1; return 1;
} }
if (strcmp(m, "__parsed") == 0) { if (strcmp(m, "__parsed") == 0) {
lua_newtable(L); lua_newtable(L);
table_of_wml_config(L, v->get_parsed_config()); luaW_pushconfig(L, v->get_parsed_config());
return 1; return 1;
} }
if (strcmp(m, "__shallow_literal") == 0) { if (strcmp(m, "__shallow_literal") == 0) {
@ -716,14 +714,14 @@ static int impl_vconfig_collect(lua_State *L)
config cfg; \ config cfg; \
accessor; \ accessor; \
lua_newtable(L); \ lua_newtable(L); \
table_of_wml_config(L, cfg); \ luaW_pushconfig(L, cfg); \
return 1; \ return 1; \
} }
#define return_cfgref_attrib(name, accessor) \ #define return_cfgref_attrib(name, accessor) \
if (strcmp(m, name) == 0) { \ if (strcmp(m, name) == 0) { \
lua_newtable(L); \ lua_newtable(L); \
table_of_wml_config(L, accessor); \ luaW_pushconfig(L, accessor); \
return 1; \ return 1; \
} }
@ -1101,7 +1099,7 @@ static int intf_get_variable(lua_State *L)
if (w.is_valid) { if (w.is_valid) {
lua_newtable(L); lua_newtable(L);
if (lua_toboolean(L, 2)) if (lua_toboolean(L, 2))
table_of_wml_config(L, w.as_container()); luaW_pushconfig(L, w.as_container());
return 1; return 1;
} }
} }
@ -1526,7 +1524,7 @@ static int impl_current_get(lua_State *L)
cfg["y2"] = ev.loc2.y + 1; cfg["y2"] = ev.loc2.y + 1;
} }
lua_newtable(L); lua_newtable(L);
table_of_wml_config(L, cfg); luaW_pushconfig(L, cfg);
return 1; return 1;
} }
@ -2231,7 +2229,7 @@ static int intf_synchronize_choice(lua_State *L)
lua_settop(L, 1); lua_settop(L, 1);
config cfg = mp_sync::get_user_choice("input", lua_synchronize(L)); config cfg = mp_sync::get_user_choice("input", lua_synchronize(L));
lua_newtable(L); lua_newtable(L);
table_of_wml_config(L, cfg); luaW_pushconfig(L, cfg);
return 1; 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); return ai::lua_ai_action_handler::create(mState,code,context);
} }
} // of namespace lua

View File

@ -25,8 +25,6 @@ class lua_ai_context;
class engine_lua; class engine_lua;
} // of namespace ai } // of namespace ai
namespace lua {
void extract_preload_scripts(config const &); void extract_preload_scripts(config const &);
class LuaKernel class LuaKernel
@ -48,6 +46,4 @@ public:
void load_package(); void load_package();
}; };
} //of namespace lua
#endif #endif

View File

@ -15,19 +15,15 @@
#ifndef SCRIPTING_LUA_API_HPP #ifndef SCRIPTING_LUA_API_HPP
#define SCRIPTING_LUA_API_HPP #define SCRIPTING_LUA_API_HPP
#include "game_events.hpp" #include <cstddef>
struct lua_State; struct lua_State;
class config;
class unit;
namespace lua {
bool luaW_pcall(lua_State *L , int nArgs, int nRets, bool allow_wml_error = false); 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); unit *luaW_tounit(lua_State *L, int index, bool only_on_map = false);
void luaW_pushconfig(lua_State *L, config const &cfg);
void table_of_wml_config(lua_State *L, config const &cfg);
bool luaW_toconfig(lua_State *L, int index, config &cfg, int tstring_meta = 0); bool luaW_toconfig(lua_State *L, int index, config &cfg, int tstring_meta = 0);
/** /**
@ -52,7 +48,4 @@ public:
unit *get(); unit *get();
}; };
} //of namespace lua
#endif #endif