From bfee085f2be86e3bd16a96c8dd70c3cc937852b1 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Tue, 6 Apr 2010 12:53:36 +0800 Subject: change tolstring to checklstring. --- lua/test-lua-plugin.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'lua/test-lua-plugin.c') 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; } -- cgit