Advertisement
Guest User

Untitled

a guest
Jun 6th, 2014
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <assert.h>
  2.  
  3.  
  4. #include <lua.h>
  5. #include <lauxlib.h>
  6. #include <lualib.h>
  7. #include <zmq.h>
  8.  
  9. const char *lua_code =
  10. "local zmq = require \"lzmq\""
  11. "local ctx = zmq.init_ctx(MY_ZMQ_CONTEXT)"
  12. "print(\"creating socket...\")"
  13. "local s = ctx:socket(zmq.REP)" // segmentation fault
  14. "print(\"created socket!\")"
  15. ;
  16.  
  17. int main()
  18. {
  19.     int r;
  20.    
  21.     void *ctx;
  22.     ctx = zmq_ctx_new();
  23.     assert(ctx);
  24.    
  25.     lua_State *L;
  26.     L = luaL_newstate();
  27.     assert(L);
  28.    
  29.     luaL_requiref(L, "_G", luaopen_base, 1);
  30.     luaL_requiref(L, "package", luaopen_package, 1);
  31.     lua_pop(L, 2);
  32.    
  33.     lua_pushlightuserdata(L, ctx);
  34.     lua_setglobal(L, "MY_ZMQ_CONTEXT");
  35.    
  36.     luaL_dostring(L, lua_code);
  37.    
  38.     lua_close(L);
  39.     r = zmq_ctx_destroy(ctx);
  40.     assert(r == 0);
  41.    
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement