diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-03-12 22:20:39 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-03-13 21:30:22 +0100 |
commit | 07c54805e8a4e9a0caafdd18af02628533764f2b (patch) | |
tree | d21b35edbe5b13fb4d85f9d869bcbf9b5a0c3cf1 /scripts | |
parent | 403472f7ad18c909e5917918ca5d93d2bb11f308 (diff) | |
download | manaserv-07c54805e8a4e9a0caafdd18af02628533764f2b.tar.gz manaserv-07c54805e8a4e9a0caafdd18af02628533764f2b.tar.xz manaserv-07c54805e8a4e9a0caafdd18af02628533764f2b.zip |
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
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/lua/libmana.lua | 25 |
1 files changed, 25 insertions, 0 deletions
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 = {} |