diff options
author | deva <deva> | 2008-08-29 10:33:53 +0000 |
---|---|---|
committer | deva <deva> | 2008-08-29 10:33:53 +0000 |
commit | dad63d9d9e3b6dc0dc0a6371558da2b0a5654fa1 (patch) | |
tree | c98f016095526a3bec06385c0c056704b370e639 | |
parent | ba73a2a96f8cc0aeecce78bc4126008a65a25b0f (diff) |
Added automap when attempting to run a non-existing map.
-rw-r--r-- | server/src/widgetgenerator.cc | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/server/src/widgetgenerator.cc b/server/src/widgetgenerator.cc index 26dcf37..334d4a8 100644 --- a/server/src/widgetgenerator.cc +++ b/server/src/widgetgenerator.cc @@ -28,6 +28,36 @@ #include "configuration.h" +static std::string automap(std::string name) +{ + std::string group; + std::string groupcheck = "if("; + + for(size_t i = 0; i < name.length(); i++) { + group += name[i]; + if(name[i] == '.') groupcheck += " and " + group; + else groupcheck += name[i]; + } + groupcheck += " and " + name + ".value and " + name + ".timestamp"; + groupcheck += ")\n"; + + std::string automapstring = + "-- Returning 0, 0 invalidates the result\n" + "value = 0\n" + "timestamp = 0\n" + "\n" + + groupcheck + + "then\n" + " value = " + name + ".value\n" + " timestamp = " + name + ".timestamp\n" + "end\n" + "return value, timestamp\n"; + + printf("Automap:\n%s\n", automapstring.c_str()); + + return automapstring; +} + static std::string send_macro_widget(Macro ¯o, Widget &widget, std::string tabs, @@ -55,6 +85,11 @@ static std::string send_macro_widget(Macro ¯o, li++; } + // Check to see if we should automap + if(luamap == "") { + luamap = automap(widget.attributes["map"]); + } + // printf("LUAMAP: %s\n", luamap.c_str()); fflush(stdout); if(luamap != "") { |