Author: nephro
Date: Sun Jul 31 02:45:49 2011
New Revision: 50504

URL: http://svn.gna.org/viewcvs/wesnoth?rev=50504&view=rev
Log:
Persistant data storage now is local to the lua_ai_context

Modified:
    trunk/data/ai/scenarios/scenario-lua-ai.cfg
    trunk/src/ai/lua/core.cpp

Modified: trunk/data/ai/scenarios/scenario-lua-ai.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/ai/scenarios/scenario-lua-ai.cfg?rev=50504&r1=50503&r2=50504&view=diff
==============================================================================
--- trunk/data/ai/scenarios/scenario-lua-ai.cfg (original)
+++ trunk/data/ai/scenarios/scenario-lua-ai.cfg Sun Jul 31 02:45:49 2011
@@ -105,10 +105,7 @@
        patrol_eval_rark = ptrl.eval
        -- End of patrol function //  patrol_gen(ai, "Rark", {{x=14, y=7}, 
{x=15, y=7}, {x=15, y=8}, {x=14, y=8}})
        
-       function persistance_check()
-               ai.data["pers"] = 182 -- we just set a variable to some value
-               ai.data["stringg"] = " = it works"
-       end
+
 >>
 [/lua]
 [/event]
@@ -162,14 +159,6 @@
        name=side 2 turn 1
        first_time_only=yes
        {MODIFY_AI_DELETE_CANDIDATE_ACTION 2 ca_loop firstca}
-[/event]
-
-[event]
-       name=side 2 turn 2
-       first_time_only=yes
-       [lua]
-               code = << persistance_check() >>
-       [/lua]
 [/event]
 
     [side]
@@ -303,9 +292,9 @@
                 code= <<
 --! ==============================================================
 ai = ...
-ai.data = {} -- @note: this shouldn't be here
-
-local my_ai = { }
+-- local data = {} -- @note: this shouldn't be here
+
+local my_ai = { data = { ["pers"] = 5, ["stringg"] = "stringg" } }
 
 
 
@@ -315,7 +304,7 @@
 
 function my_ai:stage_hello()
        wesnoth.message('hello from stage!')
-       wesnoth.message('PERSISTANCE: ' .. tostring(ai.data["pers"]) .. 
ai.data["stringg"])
+       wesnoth.message('PERSISTANCE: ' .. tostring(self.data["pers"]) .. 
self.data["stringg"])
 end
 
 function my_ai:candidate_action_evaluation_hello()

Modified: trunk/src/ai/lua/core.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai/lua/core.cpp?rev=50504&r1=50503&r2=50504&view=diff
==============================================================================
--- trunk/src/ai/lua/core.cpp (original)
+++ trunk/src/ai/lua/core.cpp Sun Jul 31 02:45:49 2011
@@ -68,19 +68,26 @@
 void lua_ai_context::get_persistent_data(config &cfg) const
 {
        int top = lua_gettop(L);
-
-       lua_getglobal(L, "ai");
+       
+       lua_pushlightuserdata(L, (void *)&aisKey);
+       lua_rawget(L, LUA_REGISTRYINDEX);
+       lua_rawgeti(L, -1, num_);
+       
        lua_getfield(L, -1, "data");
        luaW_toconfig(L, -1, cfg);
-
+       ERR_LUA << cfg << std::endl;
+       
        lua_settop(L, top);
 }
 
 void lua_ai_context::set_persistent_data(const config &cfg)
 {
        int top = lua_gettop(L);
-
-       lua_getglobal(L, "ai");
+       
+       lua_pushlightuserdata(L, (void *)&aisKey);
+       lua_rawget(L, LUA_REGISTRYINDEX);
+       lua_rawgeti(L, -1, num_);
+
        luaW_pushconfig(L, cfg);
        lua_setfield(L, -2, "data");
 
@@ -535,7 +542,7 @@
                // Aspects
                { "get_aggression",             &cfun_ai_get_aggression         
        },
                { "get_avoid",                  &cfun_ai_get_avoid              
        },
-               { "get_attack_depth",           &cfun_ai_get_attack_depth       
        }, // { "get_", &cfun_ai_get_}, little template # TODELETE
+               { "get_attack_depth",           &cfun_ai_get_attack_depth       
        },
                { "get_caution",                &cfun_ai_get_caution            
        },
                { "get_grouping",               &cfun_ai_get_grouping           
        },
                { "get_leader_aggression",      &cfun_ai_get_leader_aggression  
        },


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to