diff options
| author | Peng Wu <epico@dhcp-65-116.nay.redhat.com> | 2010-04-06 12:53:36 +0800 |
|---|---|---|
| committer | Peng Wu <alexepico@gmail.com> | 2010-05-19 10:09:32 +0800 |
| commit | bfee085f2be86e3bd16a96c8dd70c3cc937852b1 (patch) | |
| tree | 16700552b983b15345de545e2158a3e6f005c380 /lua/test-lua-plugin.c | |
| parent | 113f004efdbf39ef37a1758b862117b38ba4fedf (diff) | |
| download | ibus-libpinyin-bfee085f2be86e3bd16a96c8dd70c3cc937852b1.tar.gz ibus-libpinyin-bfee085f2be86e3bd16a96c8dd70c3cc937852b1.tar.xz ibus-libpinyin-bfee085f2be86e3bd16a96c8dd70c3cc937852b1.zip | |
change tolstring to checklstring.
Diffstat (limited to 'lua/test-lua-plugin.c')
| -rw-r--r-- | lua/test-lua-plugin.c | 28 |
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; } |
