From dad63d9d9e3b6dc0dc0a6371558da2b0a5654fa1 Mon Sep 17 00:00:00 2001 From: deva Date: Fri, 29 Aug 2008 10:33:53 +0000 Subject: Added automap when attempting to run a non-existing map. --- server/src/widgetgenerator.cc | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) 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 != "") { -- cgit v1.2.3