lua print reregister

This commit is contained in:
p.kosyh 2009-10-12 17:02:59 +00:00
parent d1cbf9f586
commit 4f16023c0a

View file

@ -288,8 +288,29 @@ static int luaB_doencfile (lua_State *L) {
return lua_gettop(L) - n;
}
static int luaB_print (lua_State *L) {
int n = lua_gettop(L); /* number of arguments */
int i;
lua_getglobal(L, "tostring");
for (i=1; i<=n; i++) {
const char *s;
lua_pushvalue(L, -1); /* function to be called */
lua_pushvalue(L, i); /* value to print */
lua_call(L, 1, 1);
s = lua_tostring(L, -1); /* get result */
if (s == NULL)
return luaL_error(L, LUA_QL("tostring") " must return a string to "LUA_QL("print"));
if (i>1) fputs("\t", stdout);
fputs(s, stdout);
lua_pop(L, 1); /* pop result */
}
fputs("\n", stdout);
return 0;
}
static const luaL_Reg base_funcs[] = {
{"doencfile", luaB_doencfile},
{"print", luaB_print}, /* for some mystic, it is needed in win version (with -debug) */
{NULL, NULL}
};