diff options
| author | ame <[email protected]> | 2025-08-01 14:25:07 -0500 |
|---|---|---|
| committer | ame <[email protected]> | 2025-08-01 14:25:07 -0500 |
| commit | 19afaa2feedaa6ec1e1774174ce752e7f2583484 (patch) | |
| tree | 5505bce2cc31f21107c27646c3c23fc1ccf4159e | |
| parent | 10ddc97d221989e107c5283e3d5df8c48a23dc26 (diff) | |
change stream modes
| -rw-r--r-- | library/lullaby/common.lua | 5 | ||||
| -rw-r--r-- | 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 @@ -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");
}
|
