11//! Registering a Zig function to be called from Lua
22
33const std = @import ("std" );
4- const lua_wrapper = @import ("lua_wrapper " );
4+ const zlua = @import ("zlua " );
55
66// It can be convenient to store a short reference to the Lua struct when
77// it is used multiple times throughout a file.
8- const Lua = lua_wrapper .Lua ;
8+ const Lua = zlua .Lua ;
99
1010// A Zig function called by Lua must accept a single *Lua parameter and must return an i32 (an error union is allowed)
1111// This is the Zig equivalent of the lua_CFunction typedef int (*lua_CFunction) (lua_State *L) in the C API
@@ -26,10 +26,10 @@ pub fn main() anyerror!void {
2626 defer lua .deinit ();
2727
2828 // Push the adder function to the Lua stack.
29- // Here we use lua_wrapper .wrap() to convert from a Zig function to the lua_CFunction required by Lua.
29+ // Here we use zlua .wrap() to convert from a Zig function to the lua_CFunction required by Lua.
3030 // This could be done automatically by pushFunction(), but that would require the parameter to be comptime-known.
31- // The call to lua_wrapper .wrap() is slightly more verbose, but has the benefit of being more flexible.
32- lua .pushFunction (lua_wrapper .wrap (adder ));
31+ // The call to zlua .wrap() is slightly more verbose, but has the benefit of being more flexible.
32+ lua .pushFunction (zlua .wrap (adder ));
3333
3434 // Push the arguments onto the stack
3535 lua .pushInteger (10 );
@@ -47,7 +47,7 @@ pub fn main() anyerror!void {
4747 std .debug .print ("the result: {}\n " , .{lua .toInteger (-1 ) catch unreachable });
4848
4949 // We can also register the function to a global and run from a Lua "program"
50- lua .pushFunction (lua_wrapper .wrap (adder ));
50+ lua .pushFunction (zlua .wrap (adder ));
5151 lua .setGlobal ("add" );
5252
5353 // We need to open the base library so the global print() is available
0 commit comments