From f54f2b0e7588e87ac4ea625eb805376311266355 Mon Sep 17 00:00:00 2001 From: Dmitry Kovalenko Date: Mon, 16 Apr 2012 20:49:02 +0000 Subject: [PATCH] LuaAI: (1) added wesnoth.is_debug_mode(); (2) disabled the LuaAI debug library usage for non-debug launch modes --- data/ai/lua/debug.lua | 10 ++++++++-- data/ai/scenarios/scenario-lua-ai.cfg | 5 +++-- src/scripting/lua.cpp | 12 ++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/data/ai/lua/debug.lua b/data/ai/lua/debug.lua index 2a0bd01c696..cff05069a68 100644 --- a/data/ai/lua/debug.lua +++ b/data/ai/lua/debug.lua @@ -1,9 +1,14 @@ --! #textdomain wesnoth -return { -- TODO: Disable the ability to register this library - -- if wesnoth started without -d argument +return { + init = function(ai) + if (not wesnoth.is_debug_mode()) then + wesnoth.message("LuaAI Error", "The LuaAI debug library is only available in debug mode") + return + end + ai.debug = {} function ai.debug.get_dst_src() @@ -27,4 +32,5 @@ return { -- TODO: Disable the ability to register this library end end + } \ No newline at end of file diff --git a/data/ai/scenarios/scenario-lua-ai.cfg b/data/ai/scenarios/scenario-lua-ai.cfg index 2f5204d16fe..19d9c204a84 100644 --- a/data/ai/scenarios/scenario-lua-ai.cfg +++ b/data/ai/scenarios/scenario-lua-ai.cfg @@ -257,12 +257,13 @@ local my_ai = { } -- data = { ["pers"] = 5, ["stringg"] = "stringg" } local ai_stdlib = wesnoth.require('ai/lua/stdlib.lua'); -ai_stdlib.init(ai) +ai_stdlib.init(ai, true) function my_ai:stage_hello() local debug_utils = wesnoth.require "~add-ons/Wesnoth_Lua_Pack/debug_utils.lua" - local mm = ai.get_dst_src() + wesnoth.message("dbg mode: " .. tostring(wesnoth.is_debug_mode())) + --local mm = ai.get_dst_src() --ai.debug.get_dst_src() --ai.debug.get_enemy_dst_src() debug_utils.dbms(ai,false,"variable",false) diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 628c2c9c348..81e40949e5a 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -1980,6 +1980,17 @@ static int intf_debug(lua_State* L) return 1; } +/** + * Returns a bool value indicating whether the + * game is launched in debug mode + * - Ret 1: bool + */ +static int intf_is_debug_mode(lua_State *L) +{ + lua_pushboolean(L, game_config::debug); + return 1; +} + /** * Removes all messages from the chat window. */ @@ -3479,6 +3490,7 @@ LuaKernel::LuaKernel(const config &cfg) { "get_variable", &intf_get_variable }, { "get_village_owner", &intf_get_village_owner }, { "highlight_hex", &intf_highlight_hex }, + { "is_debug_mode", &intf_is_debug_mode }, { "is_enemy", &intf_is_enemy }, { "match_location", &intf_match_location }, { "match_side", &intf_match_side },