Skip to content

Commit e06585e

Browse files
committed
add *Ex variant of pushFString
1 parent 6be1cbb commit e06585e

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/tests.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ test "type of and getting values" {
259259
);
260260
lua.pushFunction(ziglua.wrap(add));
261261
try expectEqualStrings("hello world", lua.pushBytesEx("hello world"));
262-
_ = lua.pushFString("%s %s %d", .{ "hello", "world", @as(i32, 10) });
262+
lua.pushFString("%s %s %d", .{ "hello", "world", @as(i32, 10) });
263263
lua.pushValue(1);
264264

265265
// test both typeof and is functions

src/ziglua.zig

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -759,10 +759,15 @@ pub const Lua = struct {
759759
lua.pushClosure(c_fn, 0);
760760
}
761761

762+
/// Push a formatted string onto the stack
763+
pub fn pushFString(lua: *Lua, fmt: [:0]const u8, args: anytype) void {
764+
_ = lua.pushFStringEx(fmt, args);
765+
}
766+
762767
/// Push a formatted string onto the stack and return a pointer to the string
763-
pub fn pushFString(lua: *Lua, fmt: [:0]const u8, args: anytype) [*]const u8 {
768+
pub fn pushFStringEx(lua: *Lua, fmt: [:0]const u8, args: anytype) [*:0]const u8 {
764769
const ptr = @call(.{}, c.lua_pushfstring, .{ lua.state, fmt } ++ args);
765-
return @ptrCast([*]const u8, ptr);
770+
return @ptrCast([*:0]const u8, ptr);
766771
}
767772

768773
/// Pushes the global environment onto the stack

0 commit comments

Comments
 (0)