2
0

lua.cpp 660 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <iostream>
  2. #include "lua.hpp"
  3. void report_errors(lua_State *L, int status)
  4. {
  5. if ( status!=0 ) {
  6. std::cerr << "-- " << lua_tostring(L, -1) << std::endl;
  7. lua_pop(L, 1); // remove error message
  8. }
  9. }
  10. int main(int argc, char** argv)
  11. {
  12. for ( int n=1; n<argc; ++n ) {
  13. const char* file = argv[n];
  14. lua_State *L = luaL_newstate();
  15. luaL_openlibs(L);
  16. std::cerr << "-- Loading file: " << file << std::endl;
  17. int s = luaL_loadfile(L, file);
  18. if ( s==0 ) {
  19. // execute Lua program
  20. s = lua_pcall(L, 0, LUA_MULTRET, 0);
  21. }
  22. report_errors(L, s);
  23. lua_close(L);
  24. std::cerr << std::endl;
  25. }
  26. return 0;
  27. }