From c49fc8a72b506972b18b3affc117f749d08b6de6 Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Tue, 1 Mar 2016 13:56:07 -0500 Subject: [PATCH] Fix wesnoth.debug_ai() (Also change some internal variable names) --- src/ai/composite/engine_lua.cpp | 2 +- src/ai/lua/core.cpp | 15 ++++++++++----- src/ai/lua/core.hpp | 1 + 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/ai/composite/engine_lua.cpp b/src/ai/composite/engine_lua.cpp index e1fd776aceeb..807b972c7af4 100644 --- a/src/ai/composite/engine_lua.cpp +++ b/src/ai/composite/engine_lua.cpp @@ -288,7 +288,7 @@ void engine_lua::push_ai_table() { if (game_config::debug) { - // TODO: Reimplement this somehow + lua_ai_context_->push_ai_table(); } } diff --git a/src/ai/lua/core.cpp b/src/ai/lua/core.cpp index 689c9f205d04..03efe0457fdd 100644 --- a/src/ai/lua/core.cpp +++ b/src/ai/lua/core.cpp @@ -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); @@ -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); } @@ -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 @@ -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); @@ -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 diff --git a/src/ai/lua/core.hpp b/src/ai/lua/core.hpp index 7f4505d2e1b1..4ed7131b655e 100644 --- a/src/ai/lua/core.hpp +++ b/src/ai/lua/core.hpp @@ -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;