summaryrefslogtreecommitdiffstats
path: root/lua/test-lua-plugin.c
diff options
context:
space:
mode:
Diffstat (limited to 'lua/test-lua-plugin.c')
-rw-r--r--lua/test-lua-plugin.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/lua/test-lua-plugin.c b/lua/test-lua-plugin.c
index c2de597..34bbef5 100644
--- a/lua/test-lua-plugin.c
+++ b/lua/test-lua-plugin.c
@@ -7,8 +7,32 @@
#include "lua-plugin.h"
+
+static const char * progname = "test-lua-plugin";
static lua_State * L = NULL;
+static void l_message (const char *pname, const char *msg) {
+ if (pname) fprintf(stderr, "%s: ", pname);
+ fprintf(stderr, "%s\n", msg);
+ fflush(stderr);
+}
+
+static int report (lua_State *L, int status) {
+ if (status && !lua_isnil(L, -1)) {
+ const char *msg = lua_tostring(L, -1);
+ if (msg == NULL) msg = "(error object is not a string)";
+ l_message(progname, msg);
+ lua_pop(L, 1);
+ }
+ return status;
+}
+
+static int run_test(lua_State *L, const char * filename){
+ int status = luaL_dofile(L, filename);
+ fprintf(stderr, "%s done.\n", filename);
+ return report(L, status);
+}
+
int main(int argc, char * argv[]){
printf("starting test...\n");
@@ -16,7 +40,9 @@ int main(int argc, char * argv[]){
L = lua_open();
lua_plugin_init(L);
- luaL_dofile(L, "test.lua");
+
+ run_test(L, "test.lua");
+
lua_plugin_fini(L);
return 0;
}