aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--library/lullaby/common.lua5
-rw-r--r--src/lua.c7
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");
}