Skip to content

Commit eb9def7

Browse files
committed
Update getMetatable to return error.NoMetatable
Other uses of error.LuaError should be updated to use more explicit errors.
1 parent dacaf21 commit eb9def7

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

src/lib.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,16 +1323,16 @@ pub const Lua = opaque {
13231323
else => getUserValue52,
13241324
};
13251325

1326-
/// If the value at the given index has a metatable, the function pushes that metatable onto the stack
1327-
/// Otherwise an error is returned
1326+
/// If the value at the given index has a metatable, the function pushes that metatable onto the stack.
1327+
/// Otherwise `error.NoMetatable` is returned.
13281328
///
13291329
/// * Pops: `0`
13301330
/// * Pushes: `(0|1)`
13311331
/// * Lua Errors: `never`
13321332
///
13331333
/// See https://www.lua.org/manual/5.4/manual.html#lua_getmetatable
1334-
pub fn getMetatable(lua: *Lua, index: i32) !void {
1335-
if (c.lua_getmetatable(@ptrCast(lua), index) == 0) return error.LuaError;
1334+
pub fn getMetatable(lua: *Lua, index: i32) error{NoMetatable}!void {
1335+
if (c.lua_getmetatable(@ptrCast(lua), index) == 0) return error.NoMetatable;
13361336
}
13371337

13381338
/// Pushes onto the stack the value `t[k]`, where `t` is the value at the given `index` and `k` is the value on the top of the stack.

src/tests.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ test "table access" {
788788
_ = lua.pushStringZ("zig");
789789
lua.rawSetTable(1);
790790

791-
try expectError(error.LuaError, lua.getMetatable(1));
791+
try expectError(error.NoMetatable, lua.getMetatable(1));
792792

793793
// create a metatable (it isn't a useful one)
794794
lua.newTable();

0 commit comments

Comments
 (0)