summaryrefslogtreecommitdiff
path: root/client/lua.cc
diff options
context:
space:
mode:
Diffstat (limited to 'client/lua.cc')
-rw-r--r--client/lua.cc136
1 files changed, 134 insertions, 2 deletions
diff --git a/client/lua.cc b/client/lua.cc
index 2753139..320d91a 100644
--- a/client/lua.cc
+++ b/client/lua.cc
@@ -90,10 +90,118 @@ static int debug(lua_State *L)
return 0;
}
-LUA::LUA(Widget **rootwidget)
+static int get_template(lua_State *L)
{
- this->rootwidget = rootwidget;
+ int n = lua_gettop(L); // number of arguments
+ if(n != 0) {
+ char errstr[512];
+ sprintf(errstr, "Number of args expected 0, got %d", n);
+ lua_pushstring(L, errstr);
+ lua_error(L);
+ return 1;
+ }
+
+ lua_getglobal(L, GLOBAL_POINTER);
+ LUA *lua = (LUA*)lua_touserdata(L, lua_gettop(L));
+
+ if(!lua) {
+ lua_pushstring(L, "No LUA pointer!");
+ lua_error(L);
+ return 1;
+ }
+
+ QString templ = lua->getTemplate();
+ lua_pushstring(L, templ.toStdString().c_str());
+
+ return 1;
+}
+
+static int get_macro(lua_State *L)
+{
+ int n = lua_gettop(L); // number of arguments
+ if(n != 0) {
+ char errstr[512];
+ sprintf(errstr, "Number of args expected 0, got %d", n);
+ lua_pushstring(L, errstr);
+ lua_error(L);
+ return 1;
+ }
+
+ lua_getglobal(L, GLOBAL_POINTER);
+ LUA *lua = (LUA*)lua_touserdata(L, lua_gettop(L));
+
+ if(!lua) {
+ lua_pushstring(L, "No LUA pointer!");
+ lua_error(L);
+ return 1;
+ }
+
+ QString macro = lua->getMacro();
+ lua_pushstring(L, macro.toStdString().c_str());
+
+ return 1;
+}
+
+static int get_user(lua_State *L)
+{
+ int n = lua_gettop(L); // number of arguments
+ if(n != 0) {
+ char errstr[512];
+ sprintf(errstr, "Number of args expected 0, got %d", n);
+ lua_pushstring(L, errstr);
+ lua_error(L);
+ return 1;
+ }
+ lua_getglobal(L, GLOBAL_POINTER);
+ LUA *lua = (LUA*)lua_touserdata(L, lua_gettop(L));
+
+ if(!lua) {
+ lua_pushstring(L, "No LUA pointer!");
+ lua_error(L);
+ return 1;
+ }
+
+ QString user = lua->getUser();
+ lua_pushstring(L, user.toStdString().c_str());
+
+ return 1;
+}
+
+static int get_patientid(lua_State *L)
+{
+ int n = lua_gettop(L); // number of arguments
+ if(n != 0) {
+ char errstr[512];
+ sprintf(errstr, "Number of args expected 0, got %d", n);
+ lua_pushstring(L, errstr);
+ lua_error(L);
+ return 1;
+ }
+
+ lua_getglobal(L, GLOBAL_POINTER);
+ LUA *lua = (LUA*)lua_touserdata(L, lua_gettop(L));
+
+ if(!lua) {
+ lua_pushstring(L, "No LUA pointer!");
+ lua_error(L);
+ return 1;
+ }
+
+ QString patientid = lua->getPatientID();
+ lua_pushstring(L, patientid.toStdString().c_str());
+
+ return 1;
+}
+
+LUA::LUA(Widget **rootwidget, QString templ, QString macro, QString user,
+ QString patientid)
+{
+ this->rootwidget = rootwidget;
+ this->templ = templ;
+ this->macro = macro;
+ this->user = user;
+ this->patientid = patientid;
L = NULL;
clear();
}
@@ -120,6 +228,10 @@ void LUA::clear()
lua_register(L, "widget", get_widget);
lua_register(L, "debug", debug);
+ lua_register(L, "template", get_template);
+ lua_register(L, "macro", get_macro);
+ lua_register(L, "user", get_user);
+ lua_register(L, "patientid", get_patientid);
register_widget(L);
register_db(L);
@@ -216,3 +328,23 @@ Widget *LUA::getWidget(QString name)
return NULL;
}
}
+
+QString LUA::getTemplate()
+{
+ return templ;
+}
+
+QString LUA::getMacro()
+{
+ return macro;
+}
+
+QString LUA::getUser()
+{
+ return user;
+}
+
+QString LUA::getPatientID()
+{
+ return patientid;
+}