From 07c54805e8a4e9a0caafdd18af02628533764f2b Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Mon, 12 Mar 2012 22:20:39 +0100 Subject: Added some convenience wrappers to libmana.lua Global functions 'warn', 'info', 'debug' as shortcuts to the respective 'log' call, which also support passing multiple parameters at the same time, which will be separated by spaces. Global tables 'map' and 'world' which provide convenient read/write access to map and world state variables. Reviewed-by: Yohann Ferreira --- scripts/lua/libmana.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'scripts/lua') diff --git a/scripts/lua/libmana.lua b/scripts/lua/libmana.lua index e9c8921..162da83 100644 --- a/scripts/lua/libmana.lua +++ b/scripts/lua/libmana.lua @@ -16,6 +16,31 @@ require "scripts/lua/libmana-constants" +-- A table that provides access to persistent variables of the current map +map = setmetatable({}, { + __index = function(_, key) + return getvar_map(key) + end, + __newindex = function(_, key, value) + setvar_map(key, value) + end, +}) + +-- A table that provides access to persistent global world variables +world = setmetatable({}, { + __index = function(_, key) + return getvar_world(key) + end, + __newindex = function(_, key, value) + setvar_world(key, value) + end, +}) + +-- Some convenient shortcuts for the different log levels +function warn(...) log(LOG_WARN, table.concat({...}, " ")) end +function info(...) log(LOG_INFO, table.concat({...}, " ")) end +function debug(...) log(LOG_DEBUG, table.concat({...}, " ")) end + -- Array containing the function registered by atinit. local init_fun = {} -- cgit