I have a module - a simple Lua wrapper. The (trimmed) code is as follows:
const clua = @cImport({
// (trimmed)
});
pub const VM = struct {
lua : ?*clua.lua_State
};
pub fn create() Error ! VM {
var s = clua.luaL_newstate() orelse return Error.CreateFailed;
clua.luaL_openlibs(s);
var vm = VM { .lua = s };
return vm;
}
Then, in my test I try to do as follows:
const lua = @import("../lua.zig"); // import the module
test "simplest" {
var l = try lua.create();
expect( l.lua != null ); // that's the problem line
}
The compiler result (trimmed from the output noise) is:
error: error is ignored
expect( l.lua != null );
~~~~~~^~~~~~~~~~~~~~~~~
note: consider using `try`, `catch`, or `if`
I don’t get it. All I’m trying to do is:
- create a
VM
structure in Zig (thelua.create
function), - simply make sure, that in case no error has been returned (the
try
part, in the previous line), the structure has been created, and its only field is not null.
The field is of type ?*clua.lua_State
, so it can be either null
, or something else, and I’d like to simply check, whether it’s not null.
Which error is ignored here?
BTW, changing the test to:
test "simplest" {
var l = try lua.create();
try expect( l.lua != null ); // here the try was added
}
“fixes” the compilation problem, but I still don’t understand, what can be an error here (without this try
)…
So I’m asking.