Advertisement
Guest User

Untitled

a guest
Oct 17th, 2014
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1.  
  2. extern "C" {
  3. #include "lua.h"
  4. #include "lualib.h"
  5. #include "lauxlib.h"
  6. #include "luajit.h"
  7. }
  8.  
  9. #include <stdlib.h>
  10. #include <conio.h>
  11.  
  12. void ffitest10()
  13. {
  14.     printf("ffi test 10 hello\n");
  15. }
  16.  
  17. extern "C" __declspec(dllimport) void lj_clib_jimontest_add(const char * name, void * ptr);
  18.  
  19. const char * luacode = R"(
  20. print("start in lua")
  21.  
  22. ffi = require("ffi")
  23. ffi.cdef
  24. [[
  25.     int printf(const char *fmt, ...);
  26.     void ffitest10();
  27. ]]
  28. setmetatable(_G, {__index = ffi.C})
  29.  
  30. printf("Hello %s!\n", "world")
  31. ffitest10()
  32.  
  33. print("end in lua")
  34. )";
  35.  
  36. int main()
  37. {
  38.     lua_State * L = lua_open();
  39.     luaL_openlibs(L);
  40.  
  41.     lj_clib_jimontest_add("ffitest10", &ffitest10);
  42.  
  43.     luaL_dostring(L, luacode);
  44.  
  45.     lua_close(L);
  46.    
  47.     printf("press any key\n");
  48.     _getch();
  49.  
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement