Skip to content

Commit

Permalink
make public some functions
Browse files Browse the repository at this point in the history
  • Loading branch information
axdank committed Dec 11, 2024
1 parent 5ceb75e commit 12475b3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 33 deletions.
36 changes: 4 additions & 32 deletions src/lib.zig
Original file line number Diff line number Diff line change
Expand Up @@ -585,34 +585,6 @@ pub fn Parsed(comptime T: type) type {
};
}

const internals = [_][]const u8{ "toStruct", "toSlice", "toTuple", "toAnyInternal" };

// wrap over some internal functions of the Lua struct
pub const Internals = blk: {
const StructField = std.builtin.Type.StructField;
var fields: [internals.len]StructField = undefined;
for (internals, 0..) |entry, i| {
const F = @field(Lua, entry);
const T = @TypeOf(F);
fields[i] = .{
.name = @ptrCast(entry),
.type = T,
.default_value = &F,
.is_comptime = false,
.alignment = @alignOf(T),
};
}

const TT = @Type(.{ .@"struct" = .{
.layout = .auto,
.fields = &fields,
.decls = &.{},
.is_tuple = false,
} });

break :blk TT{};
};

/// A Zig wrapper around the Lua C API
/// Represents a Lua state or thread and contains the entire state of the Lua interpreter
pub const Lua = opaque {
Expand Down Expand Up @@ -4561,7 +4533,7 @@ pub const Lua = opaque {
/// Converts the specified index of the lua stack to the specified
/// type if possible and returns it
/// optional allocator
fn toAnyInternal(lua: *Lua, comptime T: type, a: ?std.mem.Allocator, comptime allow_alloc: bool, index: i32) !T {
pub fn toAnyInternal(lua: *Lua, comptime T: type, a: ?std.mem.Allocator, comptime allow_alloc: bool, index: i32) !T {
const stack_size_on_entry = lua.getTop();
defer {
if (lua.getTop() != stack_size_on_entry) {
Expand Down Expand Up @@ -4762,7 +4734,7 @@ pub const Lua = opaque {
}

/// Converts a lua array to a zig slice, memory is owned by the caller
fn toSlice(lua: *Lua, comptime ChildType: type, a: std.mem.Allocator, raw_index: i32) ![]ChildType {
pub fn toSlice(lua: *Lua, comptime ChildType: type, a: std.mem.Allocator, raw_index: i32) ![]ChildType {
const index = lua.absIndex(raw_index);

if (!lua.isTable(index)) {
Expand All @@ -4783,7 +4755,7 @@ pub const Lua = opaque {
}

/// Converts value at given index to a zig struct tuple if possible
fn toTuple(lua: *Lua, comptime T: type, a: ?std.mem.Allocator, comptime allow_alloc: bool, raw_index: i32) !T {
pub fn toTuple(lua: *Lua, comptime T: type, a: ?std.mem.Allocator, comptime allow_alloc: bool, raw_index: i32) !T {
const stack_size_on_entry = lua.getTop();
defer std.debug.assert(lua.getTop() == stack_size_on_entry);

Expand Down Expand Up @@ -4826,7 +4798,7 @@ pub const Lua = opaque {
}

/// Converts value at given index to a zig struct if possible
fn toStruct(lua: *Lua, comptime T: type, a: ?std.mem.Allocator, comptime allow_alloc: bool, raw_index: i32) !T {
pub fn toStruct(lua: *Lua, comptime T: type, a: ?std.mem.Allocator, comptime allow_alloc: bool, raw_index: i32) !T {
const stack_size_on_entry = lua.getTop();
defer std.debug.assert(lua.getTop() == stack_size_on_entry);

Expand Down
2 changes: 1 addition & 1 deletion src/tests.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2443,7 +2443,7 @@ test "toAny from struct with fromLua" {
foo: i32,

pub fn fromLua(l: *Lua, a: ?std.mem.Allocator, i: i32) !Self {
return try ziglua.Internals.toStruct(l, Self, a, false, i);
return try l.toStruct(Self, a, false, i);
}
},
};
Expand Down

0 comments on commit 12475b3

Please sign in to comment.