Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2015
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. function lua_sum(x,y,z)
  2. return x+y+z
  3. end
  4.  
  5. #include "D:/luac/include/lua.h"
  6. #include "D:/luac/include/lualib.h"
  7. #include "D:/luac/include/lauxlib.h"
  8. #include <stdlib.h>
  9.  
  10. #pragma comment(lib,"D:/luac/lib/lua51.lib")
  11.  
  12.  
  13.  
  14.  
  15.  
  16. int main(void)
  17. {
  18.  
  19. lua_State *L = luaL_newstate();
  20. luaopen_base(L);
  21. luaL_openlibs(L);
  22.  
  23. int error = luaL_dofile(L, "add4c.lua");
  24.  
  25.  
  26. double r;
  27. for (int i = 0; i <= 200; i++){
  28. lua_getglobal(L, "lua_sum");
  29. lua_pushnumber(L, i+1);
  30. lua_pushnumber(L, i+2);
  31. lua_pushnumber(L, i+3);
  32. lua_call(L, 3, 1);
  33. r = lua_tonumber(L, -1);
  34. printf("%dn", i);
  35. lua_pop(L, 4);
  36. }
  37.  
  38. lua_close(L);
  39.  
  40.  
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement