diff options
Diffstat (limited to 'lbaselib.c')
-rw-r--r-- | lbaselib.c | 16 |
1 files changed, 5 insertions, 11 deletions
@@ -24,18 +24,12 @@ | |||
24 | static int luaB_print (lua_State *L) { | 24 | static int luaB_print (lua_State *L) { |
25 | int n = lua_gettop(L); /* number of arguments */ | 25 | int n = lua_gettop(L); /* number of arguments */ |
26 | int i; | 26 | int i; |
27 | lua_getglobal(L, "tostring"); | 27 | for (i = 1; i <= n; i++) { /* for each argument */ |
28 | for (i=1; i<=n; i++) { | ||
29 | const char *s; | ||
30 | size_t l; | 28 | size_t l; |
31 | lua_pushvalue(L, -1); /* function to be called */ | 29 | const char *s = luaL_tolstring(L, i, &l); /* convert it to string */ |
32 | lua_pushvalue(L, i); /* value to print */ | 30 | if (i > 1) /* not the first element? */ |
33 | lua_call(L, 1, 1); | 31 | lua_writestring("\t", 1); /* add a tab before it */ |
34 | s = lua_tolstring(L, -1, &l); /* get result */ | 32 | lua_writestring(s, l); /* print it */ |
35 | if (s == NULL) | ||
36 | return luaL_error(L, "'tostring' must return a string to 'print'"); | ||
37 | if (i>1) lua_writestring("\t", 1); | ||
38 | lua_writestring(s, l); | ||
39 | lua_pop(L, 1); /* pop result */ | 33 | lua_pop(L, 1); /* pop result */ |
40 | } | 34 | } |
41 | lua_writeline(); | 35 | lua_writeline(); |