Revert "LuaAI: (1) persistent storage mechanism now available and working properly (2) old/incomplete mechanism not removed, subject to future deprecation"

This reverts commit 754f2c2b3d.
This commit is contained in:
mattsc 2013-05-13 13:15:06 -07:00
parent 8e872d3bbe
commit 78f753e4dc
5 changed files with 11 additions and 45 deletions

View file

@ -2,7 +2,7 @@
return {
get_ai = function(ai)
local my_ai = {}
local my_ai = { }
local ai_stdlib = wesnoth.require('ai/lua/stdlib.lua')
ai_stdlib.init(ai, true)

View file

@ -10,11 +10,6 @@ end
function example_ca:exec(ai)
wesnoth.message("External CA exec attacks!")
if (ai.store.n == nil) then
ai.store.n = 0
end
ai.store.n = ai.store.n + 5
wesnoth.message("xtcastore = ", tostring(ai.store.n))
ai.attack(2, 12, 3, 12, 1, 1) -- showcasing the presence of the AI table
end

View file

@ -4,9 +4,6 @@ return {
init = function(ai, dbg)
-- Initialize persistent storage table
ai.store = {}
-- Initialize the cache system for LuaAI context
local cache = wesnoth.require("ai/lua/cache.lua")
cache.init(ai)

View file

@ -240,8 +240,8 @@ engine_lua::engine_lua( readonly_context &context, const config &cfg )
{
name_ = "lua";
config data(cfg.child_or_empty("data"));
if (lua_ai_context_ && !data.empty()) { // The context might be NULL if the config contains errors
if (lua_ai_context_) { // The context might be NULL if the config contains errors
lua_ai_context_->set_persistent_data(data);
}
}
@ -251,7 +251,7 @@ std::string engine_lua::get_engine_code(const config &cfg) const
if (cfg.has_attribute("code")) {
return cfg["code"].str();
}
// If there is no engine defined we create a dummy engine
// If there is no engine defined we create a dummy engine
std::string code = "local ai = ... local m_ai = wesnoth.require(\"ai/lua/dummy_engine_lua.lua\") return m_ai.get_ai(ai)";
return code;
}
@ -368,11 +368,7 @@ config engine_lua::to_config() const
config cfg = engine::to_config();
cfg["id"] = get_id();
// Some AI's have no engine code
if (!this->code_.empty()) {
cfg["code"] = this->code_;
}
cfg["code"] = this->code_;
if (lua_ai_context_) {
config data = config();

View file

@ -72,23 +72,11 @@ void lua_ai_context::get_persistent_data(config &cfg) const
lua_pushlightuserdata(L, static_cast<void *>(const_cast<char *>(&aisKey)));
lua_rawget(L, LUA_REGISTRYINDEX);
lua_rawgeti(L, -1, num_);
int engine_index = lua_gettop(L);
config data = config();
lua_getfield(L, -1, "data");
luaW_toconfig(L, -1, data);
lua_settop(L, engine_index);
config store = config();
lua_getfield(L, -1, "get_ai");
lua_pushvalue(L, -2);
lua_call(L, 1, 1);
lua_getfield(L, -1, "store");
luaW_toconfig(L, -1, store);
luaW_toconfig(L, -1, cfg);
lua_settop(L, top);
cfg.add_child("lua_store") = store;
cfg.add_child("lua_engine_data") = data;
}
void lua_ai_context::set_persistent_data(const config &cfg)
@ -98,20 +86,10 @@ void lua_ai_context::set_persistent_data(const config &cfg)
lua_pushlightuserdata(L, static_cast<void *>(const_cast<char *>(&aisKey)));
lua_rawget(L, LUA_REGISTRYINDEX);
lua_rawgeti(L, -1, num_);
int engine_index = lua_gettop(L);
config data = cfg.child("lua_engine_data");
luaW_pushconfig(L, data);
luaW_pushconfig(L, cfg);
lua_setfield(L, -2, "data");
lua_settop(L, engine_index);
config store = cfg.child("lua_store");
lua_getfield(L, -1, "get_ai");
lua_pushvalue(L, -2);
lua_call(L, 1, 1);
luaW_pushconfig(L, store);
lua_setfield(L, -2, "store");
lua_settop(L, top);
}
static ai::engine_lua &get_engine(lua_State *L)