From 259fc18ebdbefcad0940422180a3c68d1cd9ef04 Mon Sep 17 00:00:00 2001 From: flowtron Date: Sun, 17 Apr 2011 15:49:45 +0000 Subject: [PATCH] getvar - friend of getalias git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@6266 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/command.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/source/src/command.cpp b/source/src/command.cpp index 1585ebcd..8c0c1bbd 100644 --- a/source/src/command.cpp +++ b/source/src/command.cpp @@ -290,6 +290,32 @@ void _getalias(char *name) } COMMANDN(getalias, _getalias, ARG_1STR); +void _getvar(char *name) +{ + string resstr; + resstr[0] = '\0'; + ident *id = idents->access(name); + if(id) + { + switch(id->type) + { + case ID_VAR: + formatstring(resstr)("%d", *id->storage.i); + break; + case ID_FVAR: + formatstring(resstr)("%.3f", *id->storage.f); + break; + case ID_SVAR: + formatstring(resstr)("%s", *id->storage.s); + break; + + default: break; + } + } + result(resstr); +} +COMMANDN(getvar, _getvar, ARG_1STR); + bool addcommand(const char *name, void (*fun)(), int narg) { if(!idents) idents = new hashtable;