1
0

main.cpp 531 B

12345678910111213141516171819202122232425262728
  1. #include "lua_bridge.hpp"
  2. using namespace pkpy;
  3. int main(){
  4. VM* vm = new VM();
  5. // create lua state
  6. lua_State* L = luaL_newstate();
  7. luaL_openlibs(L);
  8. // initialize lua bridge
  9. initialize_lua_bridge(vm, L);
  10. // dostring to get _G
  11. vm->exec("import lua");
  12. vm->exec("g = lua.dostring('return _G')");
  13. // create a table
  14. vm->exec("t = lua.Table()");
  15. vm->exec("t.a = 1");
  16. vm->exec("t.b = 2");
  17. // call lua function
  18. vm->exec("g.print(t.a + t.b)"); // 3
  19. return 0;
  20. }