Skip to content

Commit

Permalink
Fix wesnoth.debug_ai()
Browse files Browse the repository at this point in the history
(Also change some internal variable names)
  • Loading branch information
CelticMinstrel authored and mattsc committed Mar 22, 2016
1 parent 1d7c1c7 commit c49fc8a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/ai/composite/engine_lua.cpp
Expand Up @@ -288,7 +288,7 @@ void engine_lua::push_ai_table()
{
if (game_config::debug)
{
// TODO: Reimplement this somehow
lua_ai_context_->push_ai_table();
}
}

Expand Down
15 changes: 10 additions & 5 deletions src/ai/lua/core.cpp
Expand Up @@ -72,7 +72,7 @@ void lua_ai_context::get_arguments(config &cfg) const
lua_rawget(L, LUA_REGISTRYINDEX);
lua_rawgeti(L, -1, num_);

lua_getfield(L, -1, "args");
lua_getfield(L, -1, "params");
luaW_toconfig(L, -1, cfg);

lua_settop(L, top);
Expand All @@ -87,7 +87,7 @@ void lua_ai_context::set_arguments(const config &cfg)
lua_rawgeti(L, -1, num_);

luaW_pushconfig(L, cfg);
lua_setfield(L, -2, "args");
lua_setfield(L, -2, "params");

lua_settop(L, top);
}
Expand Down Expand Up @@ -131,6 +131,11 @@ static ai::readonly_context &get_readonly_context(lua_State *L)
return get_engine(L).get_readonly_context();
}

void lua_ai_context::push_ai_table()
{
lua_ai_load ctx(*this, false);
}

static void push_location_key(lua_State* L, const map_location& loc)
{
// This should be factored out. The same function is defined in data/lua/location_set.lua
Expand Down Expand Up @@ -1027,7 +1032,7 @@ lua_ai_context* lua_ai_context::create(lua_State *L, char const *code, ai::engin
//push data table here
size_t idx = generate_and_push_ai_state(L, engine); // [-1: AI state -2: AI code]
lua_pushvalue(L, -2); // [-1: AI code -2: AI state -3: AI code]
lua_setfield(L, -2, "update_state"); // [-1: AI state -2: AI code]
lua_setfield(L, -2, "update_self"); // [-1: AI state -2: AI code]
lua_pushlightuserdata(L, engine);
lua_setfield(L, -2, "engine"); // [-1: AI state -2: AI code]
lua_pop(L, 2);
Expand All @@ -1039,8 +1044,8 @@ void lua_ai_context::update_state()
lua_ai_load ctx(*this, true); // [-1: AI state table]

// Load the AI code and arguments
lua_getfield(L, -1, "update_state"); // [-1: AI code -2: AI state]
lua_getfield(L, -2, "args"); // [-1: Arguments -2: AI code -3: AI state]
lua_getfield(L, -1, "update_self"); // [-1: AI code -2: AI state]
lua_getfield(L, -2, "params"); // [-1: Arguments -2: AI code -3: AI state]
lua_getfield(L, -3, "data"); // [-1: Persistent data -2: Arguments -3: AI code -4: AI state]

// Call the function
Expand Down
1 change: 1 addition & 0 deletions src/ai/lua/core.hpp
Expand Up @@ -49,6 +49,7 @@ class lua_ai_context
void set_persistent_data(const config &);
void get_arguments(config &) const;
void set_arguments(const config &);
void push_ai_table();
static void init(lua_State *L);
friend class ::game_lua_kernel;
friend class lua_ai_load;
Expand Down

0 comments on commit c49fc8a

Please sign in to comment.