From 19afaa2feedaa6ec1e1774174ce752e7f2583484 Mon Sep 17 00:00:00 2001 From: ame Date: Fri, 1 Aug 2025 14:25:07 -0500 Subject: change stream modes --- library/lullaby/common.lua | 5 +++-- src/lua.c | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/library/lullaby/common.lua b/library/lullaby/common.lua index 936feb9..96be2d6 100644 --- a/library/lullaby/common.lua +++ b/library/lullaby/common.lua @@ -9,8 +9,9 @@ meta.stream = {} ---sends the rest of a streams contents to a file ---@param T stream ---@param filename string ----@param bytes integer? max amount to read before stopping -function meta.stream.file(T, filename, bytes) end +---@param bytes integer? max amount to read before stopping, 0 if nil +---@param mode string? what mode to open the file, w if nil +function meta.stream.file(T, filename, bytes, mode) end ---reads bytes from a stream ---@param T stream diff --git a/src/lua.c b/src/lua.c index 3d35858..ef3c032 100644 --- a/src/lua.c +++ b/src/lua.c @@ -59,10 +59,15 @@ int _stream_file(lua_State* L){ const int CHUNK_SIZE = 4096; uint64_t maxlen = 0; uint64_t totallen = 0; + const char* mode = "w"; if(lua_gettop(L) > 2){ maxlen = lua_tointeger(L, 3); } + if(lua_gettop(L) > 3){ + mode = lua_tostring(L, 4); + } + lua_pushstring(L, "_read"); lua_gettable(L, 1); stream_read_function rf = lua_touserdata(L, -1); @@ -73,7 +78,7 @@ int _stream_file(lua_State* L){ const char* filename = lua_tostring(L, 2); FILE *f; - f = fopen(filename, "w"); + f = fopen(filename, mode); if(f == NULL){ luaI_error(L, -1, "unable to open file"); } -- cgit v1.2.3