summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2012-05-03 14:46:48 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2012-05-03 14:46:48 +0200
commit9833601f819239aa1034d2c5189214f29445dcb0 (patch)
treefdacf684f5da4e60ea3e850dcfc08c08877c4aa7
parentda3e1bec8f45feddaee41ba02562207f4b7ad1f7 (diff)
Add debug function for use in lua scripts
-rw-r--r--server/src/luascript.cc28
1 files changed, 21 insertions, 7 deletions
diff --git a/server/src/luascript.cc b/server/src/luascript.cc
index f4aef40..6ba52a9 100644
--- a/server/src/luascript.cc
+++ b/server/src/luascript.cc
@@ -35,6 +35,19 @@
#define GLOBAL_POINTER "_pracroGlobalLUAObjectPointerThisShouldBeANameThatIsNotAccidentallyOverwritten"
+static int _debug(lua_State *L)
+{
+ Pracro::checkParameters(L,
+ Pracro::T_STRING,
+ Pracro::T_END);
+
+ std::string msg = lua_tostring(L, lua_gettop(L));
+
+ DEBUG(luascript, "%s\n", msg.c_str());
+
+ return 0;
+}
+
static int _value(lua_State *L)
{
Pracro::checkParameters(L,
@@ -145,7 +158,7 @@ void LUAScript::init()
L = luaL_newstate();
if(L == NULL) {
- ERR(luaresume, "Could not create LUA state.\n");
+ ERR(luascript, "Could not create LUA state.\n");
throw Exception("Could not create LUA state.");
}
@@ -159,6 +172,7 @@ void LUAScript::init()
lua_register(L, "template", _template);
lua_register(L, "macro", _macro);
lua_register(L, "user", _user);
+ lua_register(L, "debug", _debug);
register_praxisd(L);
}
@@ -214,7 +228,7 @@ void LUAScript::run()
}
if(L == NULL) {
- ERR(luaresume, "LUA state not initialized!");
+ ERR(luascript, "LUA state not initialized!");
return;
}
@@ -227,16 +241,16 @@ void LUAScript::run()
std::string codename = name();
if(i->second != "") codename += ": " + i->second;
- DEBUG(luaresume, "Running %s: %s\n", codename.c_str(), program.c_str());
+ DEBUG(luascript, "Running %s: %s\n", codename.c_str(), program.c_str());
if(luaL_loadbuffer(L, program.c_str(), program.size(), codename.c_str())) {
- ERR(luaresume, "loadbufer: %s\n", lua_tostring(L, lua_gettop(L)));
+ ERR(luascript, "loadbuffer: %s\n", lua_tostring(L, lua_gettop(L)));
throw Exception(lua_tostring(L, lua_gettop(L)));
}
// Run the loaded code
if(lua_pcall(L, 0, LUA_MULTRET, 0)) {
- ERR(luaresume, "pcall: %s\n" , lua_tostring(L, lua_gettop(L)));
+ ERR(luascript, "pcall: %s\n" , lua_tostring(L, lua_gettop(L)));
throw Exception(lua_tostring(L, lua_gettop(L)));
}
@@ -247,12 +261,12 @@ void LUAScript::run()
std::string LUAScript::resultString() throw(Exception)
{
if(top != lua_gettop(L) - 1) {
- ERR(luaresume, "Program did not return a single value.\n");
+ ERR(luascript, "Program did not return a single value.\n");
throw Exception("Program did not return a single value.");
}
if(lua_isstring(L, lua_gettop(L)) == false) {
- ERR(luaresume, "Program did not return a string value.\n");
+ ERR(luascript, "Program did not return a string value.\n");
throw Exception("Program did not return a string value.");
}