Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. // build with:
  2. // zig build-lib -dynamic --library c -isystem /usr/include/ mylib.zig
  3. // mv libmylib.so.0.0.0 mylib.so
  4. //
  5. // run with:
  6. // lua -e 'mylib=require"mylib"; mylib.foo()'
  7.  
  8. const std = @import("std");
  9.  
  10. const lua = @cImport({
  11. @cInclude("lua.h");
  12. @cInclude("lauxlib.h");
  13. });
  14.  
  15. extern fn foo(L: ?*lua.lua_State) c_int {
  16. return 0;
  17. }
  18.  
  19. extern fn bar(L: ?*lua.lua_State) c_int {
  20. return 0;
  21. }
  22.  
  23. const lib = []lua.luaL_Reg{
  24. lua.luaL_Reg{ .name = c"foo", .func = foo },
  25. lua.luaL_Reg{ .name = c"bar", .func = bar },
  26. lua.luaL_Reg{ .name = 0, .func = null },
  27. };
  28.  
  29. export fn luaopen_mylib(L: *lua.lua_State) c_int {
  30. lua.lua_createtable(L, 0, lib.len - 1);
  31. lua.luaL_setfuncs(L, &lib[0], 0);
  32. return 1;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement