summaryrefslogtreecommitdiffstats
path: root/lem/io/core.c
diff options
context:
space:
mode:
Diffstat (limited to 'lem/io/core.c')
-rw-r--r--lem/io/core.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/lem/io/core.c b/lem/io/core.c
index 4844bac..5917b64 100644
--- a/lem/io/core.c
+++ b/lem/io/core.c
@@ -104,6 +104,23 @@ error:
return luaL_argerror(T, idx, "invalid permissions");
}
+static void
+io_print(lua_State *T)
+{
+ int orig_top = lua_gettop(T);
+ luaL_checktype(T, 1, LUA_TUSERDATA);
+ lua_checkstack(T, (orig_top - 1) * 3 + 1);
+ for (int i=2;i<=orig_top;i++) {
+ if (i>2) lua_pushliteral(T, "\t");
+ (void)luaL_tolstring(T, i, NULL);
+ }
+ lua_pushliteral(T, "\n");
+ if (orig_top > 1) {
+ lua_rotate(T, 2, 1 - orig_top);
+ lua_settop(T, (orig_top - 1) * 2 + 1);
+ }
+}
+
#include "file.c"
#include "stream.c"
#include "server.c"
@@ -600,6 +617,9 @@ luaopen_lem_io_core(lua_State *L)
/* mt.lock = <file_lock> */
lua_pushcfunction(L, file_lock);
lua_setfield(L, -2, "lock");
+ /* mt.print = <file_print> */
+ lua_pushcfunction(L, file_print);
+ lua_setfield(L, -2, "print");
/* insert table */
lua_setfield(L, -2, "File");
@@ -637,6 +657,9 @@ luaopen_lem_io_core(lua_State *L)
/* mt.sendfile = <stream_sendfile> */
lua_pushcfunction(L, stream_sendfile);
lua_setfield(L, -2, "sendfile");
+ /* mt.print = <stream_print> */
+ lua_pushcfunction(L, stream_print);
+ lua_setfield(L, -2, "print");
/* insert io.stdin stream */
push_stdstream(L, STDIN_FILENO);
lua_setfield(L, -3, "stdin");