Skip to content

function l_print patched #3

Description

@kenlo88

l_print in functions/print.c is patched so that it behaves as the original print function in lua by shamelessly copying lua source.

int l_print(lua_State *L) {
    int n = lua_gettop(L);	/* arg_n renamed as n */
    int i;
    lua_getglobal(L, "tostring");
    for (i=1; i<=n; i++) {
	const char *s;
	size_t l;
	lua_pushvalue(L, -1);  /* function to be called */
	lua_pushvalue(L, i);   /* value to print */
	lua_call(L, 1, 1);
	s = lua_tolstring(L, -1, &l);  /* get result */
	if (s == NULL) {
		lua_pushstring(L, "must return a string to print");
		lua_error(L);
		return 0;
	}
	if (i>1) FCGX_FPrintF(request.out, "\t");
	FCGX_FPrintF(request.out, s);
	lua_pop(L, 1);  /* pop result */
    }
    return 1;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions