Author: nephro
Date: Mon Apr 2 22:51:38 2012
New Revision: 53757
URL: http://svn.gna.org/viewcvs/wesnoth?rev=53757&view=rev
Log:
(1)Fixed an infinite loop bug (2) Fixed methods, that provided wrong objects to
Lua
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=53757&r1=53756&r2=53757&view=diff
==============================================================================
--- trunk/data/ai/scenarios/scenario-lua-ai.cfg (original)
+++ trunk/data/ai/scenarios/scenario-lua-ai.cfg Mon Apr 2 22:51:38 2012
@@ -313,45 +313,54 @@
ai = ...
-- local data = {} -- @note: this shouldn't be here
-local my_ai = { data = { ["pers"] = 5, ["stringg"] = "stringg" } }
-
-
+local my_ai = { }
+
+-- data = { ["pers"] = 5, ["stringg"] = "stringg" }
local ai_stdlib = wesnoth.require('ai/lua/stdlib.lua');
ai_stdlib.init(ai)
function my_ai:stage_hello()
- --wesnoth.message('hello from stage!')
+ wesnoth.message('hello from stage!')
--wesnoth.message('PERSISTANCE: ' .. tostring(self.data["pers"]) ..
self.data["stringg"])
- local tg = ai.get_targets()
- for k,v in pairs(tg) do
- if v.type==3 or v.type==4 then
- wesnoth.message(tg[k].type .. " " .. tg[k].value .. " "
.. tg[k].loc.x .. " " ..tg[k].loc.y)
- end
- end
+ --local tg = ai.get_targets()
+ --for k,v in pairs(tg) do
+ -- if v.type==3 or v.type==4 then
+ -- wesnoth.message(tg[k].type .. " " .. tg[k].value .. " "
.. tg[k].loc.x .. " " ..tg[k].loc.y)
+ -- end
+ --end
+
+end
+
+function my_ai:candidate_action_evaluation_hello()
+ wesnoth.message('hello from candidate action evaluation!')
-end
-
-function my_ai:candidate_action_evaluation_hello()
- --wesnoth.message('hello from candidate action evaluation!')
return 42, {test=123}
end
function my_ai:candidate_action_execution_hello(cfg)
- -- wesnoth.message('hello from candidate action execution!')
+ wesnoth.message('hello from candidate action execution!')
--wesnoth.message('test value is ') -- .. cfg.test) -- ERROR: cfg.test
is nil here
self:do_moves()
end
function my_ai:candidate_action_evaluation_hello2()
- --wesnoth.message('hello from second candidate action evaluation!')
+ wesnoth.message('hello from second candidate action evaluation!')
+ wesnoth.message("LuaDebug", "hello")
+ local map = ai.get_enemy_dstsrc()
+ wesnoth.message("LuaDebug", "hello " .. #map)
+ for dst,src in pairs(map) do
+ for k,v in pairs(src) do
+ wesnoth.message("LuaDebug", dst.x .. "," .. dst.y .. "
-> " .. v.x .. "," .. v.y)
+ end
+ end
return 99
end
function my_ai:candidate_action_execution_hello2()
- --wesnoth.message('hello from second candidate action execution!')
+ wesnoth.message('hello from second candidate action execution!')
self:do_moves()
end
Modified: trunk/src/ai/lua/core.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai/lua/core.cpp?rev=53757&r1=53756&r2=53757&view=diff
==============================================================================
--- trunk/src/ai/lua/core.cpp (original)
+++ trunk/src/ai/lua/core.cpp Mon Apr 2 22:51:38 2012
@@ -502,13 +502,21 @@
static void push_move_map(lua_State *L, const move_map& m)
{
+ lua_createtable(L, 0, 0); // the main table
+
+ if (m.empty())
+ {
+ return;
+ }
+
move_map::const_iterator it = m.begin();
int index = 1;
- lua_createtable(L, 0, 0); // the main table
-
- do {
+
+
+ do
+ {
map_location key = it->first;
push_map_location(L, key);
@@ -540,7 +548,7 @@
static int cfun_ai_get_srcdst(lua_State *L)
{
- move_map src_dst = get_readonly_context(L).get_dstsrc();
+ move_map src_dst = get_readonly_context(L).get_srcdst();
push_move_map(L, src_dst);
return 1;
}
@@ -554,7 +562,7 @@
static int cfun_ai_get_enemy_srcdst(lua_State *L)
{
- move_map enemy_src_dst = get_readonly_context(L).get_enemy_dstsrc();
+ move_map enemy_src_dst = get_readonly_context(L).get_enemy_srcdst();
push_move_map(L, enemy_src_dst);
return 1;
}
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits