Skip to content

Commit 8a61f77

Browse files
committed
Add support for loading content from stdin
1 parent 0dd090d commit 8a61f77

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/root.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,8 +1872,8 @@ pub const Lua = opaque {
18721872
/// From: `int luaL_loadfile(lua_State *L, const char *filename);`
18731873
/// Refer to: https://www.lua.org/manual/5.1/manual.html#luaL_loadfile
18741874
/// Stack Behavior: `[-0, +1, m]`
1875-
pub fn loadFile(lua: *Lua, filename: [:0]const u8) LoadFileError!void {
1876-
const res = c.luaL_loadfile(asState(lua), filename);
1875+
pub fn loadFile(lua: *Lua, filename: ?[:0]const u8) LoadFileError!void {
1876+
const res = c.luaL_loadfile(asState(lua), if (filename) |f| f.ptr else null);
18771877
return interpretLoadFileRes(res, "loadFile()");
18781878
}
18791879

@@ -1953,12 +1953,12 @@ pub const Lua = opaque {
19531953

19541954
/// Loads the Lua chunk in the given file and, if there are no errors, pushes the compiled chunk as a Lua
19551955
/// function on top of the stack before executing it using `callProtected()`. Essentially, `doFile()` executes
1956-
/// the Lua code in the given file.
1956+
/// the Lua code in the given file. If `filename` is null, `doFile()` loads from standard input.
19571957
///
19581958
/// From: `int luaL_dofile(lua_State *L, const char *filename);`
19591959
/// Refer to: https://www.lua.org/manual/5.1/manual.html#luaL_dofile
19601960
/// Stack Behavior: `[-0, +?, m]`
1961-
pub fn doFile(lua: *Lua, filename: [:0]const u8) DoFileError!void {
1961+
pub fn doFile(lua: *Lua, filename: ?[:0]const u8) DoFileError!void {
19621962
try lua.loadFile(filename);
19631963
return lua.callProtected(0, Lua.MultipleReturn, 0);
19641964
}

0 commit comments

Comments
 (0)