add *Ex variant of pushFString

This commit is contained in:
Nathan Craddock 2022-07-06 19:29:18 -06:00
parent 6be1cbbecc
commit e06585e9ed
No known key found for this signature in database
GPG Key ID: ABE41A31B52E9DA7
2 changed files with 8 additions and 3 deletions

View File

@ -259,7 +259,7 @@ test "type of and getting values" {
);
lua.pushFunction(ziglua.wrap(add));
try expectEqualStrings("hello world", lua.pushBytesEx("hello world"));
_ = lua.pushFString("%s %s %d", .{ "hello", "world", @as(i32, 10) });
lua.pushFString("%s %s %d", .{ "hello", "world", @as(i32, 10) });
lua.pushValue(1);
// test both typeof and is functions

View File

@ -759,10 +759,15 @@ pub const Lua = struct {
lua.pushClosure(c_fn, 0);
}
/// Push a formatted string onto the stack
pub fn pushFString(lua: *Lua, fmt: [:0]const u8, args: anytype) void {
_ = lua.pushFStringEx(fmt, args);
}
/// Push a formatted string onto the stack and return a pointer to the string
pub fn pushFString(lua: *Lua, fmt: [:0]const u8, args: anytype) [*]const u8 {
pub fn pushFStringEx(lua: *Lua, fmt: [:0]const u8, args: anytype) [*:0]const u8 {
const ptr = @call(.{}, c.lua_pushfstring, .{ lua.state, fmt } ++ args);
return @ptrCast([*]const u8, ptr);
return @ptrCast([*:0]const u8, ptr);
}
/// Pushes the global environment onto the stack