Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4699,7 +4699,7 @@ pub const Lua = opaque {
inline for (info.@"fn".params, 0..) |param, i| {
const param_info = @typeInfo(param.type.?);
//only use the overhead of creating the arena allocator if needed
if (comptime param_info == .pointer and param_info.pointer.size != .One) {
if (comptime param_info == .pointer and param_info.pointer.size != .one) {
const parsed = lua.toAnyAlloc(param.type.?, (i + 1)) catch |err| {
lua.raiseErrorStr(@errorName(err), .{});
};
Expand Down
12 changes: 12 additions & 0 deletions src/tests.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2656,6 +2656,10 @@ fn bar(a: i32, b: i32) !i32 {
return a + b;
}

fn baz(a: []const u8) usize {
return a.len;
}

test "autoPushFunction" {
var lua = try Lua.init(testing.allocator);
defer lua.deinit();
Expand All @@ -2667,17 +2671,25 @@ test "autoPushFunction" {
lua.autoPushFunction(bar);
lua.setGlobal("bar");

lua.autoPushFunction(baz);
lua.setGlobal("baz");

try lua.doString(
\\result = foo(1, 2)
);
try lua.doString(
\\local status, result = pcall(bar, 1, 2)
);

try lua.doString(
\\result = baz("test")
);

//automatic api construction
const my_api = .{
.foo = foo,
.bar = bar,
.baz = baz,
};

try lua.pushAny(my_api);
Expand Down