| 450 | static bool use_type_check_compile = true; |
| 451 | |
| 452 | static int handle_script(lua_State *L, char **argv, bool is_contract=false) { |
| 453 | int status; |
| 454 | const char *fname = argv[0]; |
| 455 | if (strcmp(fname, "-") == 0 && strcmp(argv[-1], "--") != 0) |
| 456 | fname = NULL; /* stdin */ |
| 457 | bool is_bytecode_file = luaL_is_bytecode_file(L, fname); |
| 458 | if (is_bytecode_file) |
| 459 | { |
| 460 | status = luaL_loadfile(L, fname); |
| 461 | if (status == LUA_OK) { |
| 462 | int n = pushargs(L); /* push arguments to script */ |
| 463 | status = docall(L, n, LUA_MULTRET); |
| 464 | } |
| 465 | return report(L, status); |
| 466 | } |
| 467 | else |
| 468 | { |
| 469 | std::string out_fname = std::string(fname) + ".out"; |
| 470 | char error[LUA_COMPILE_ERROR_MAX_LENGTH + 1]; |
| 471 | memset(error, 0x0, sizeof(char) * (LUA_COMPILE_ERROR_MAX_LENGTH + 1)); |
| 472 | // TODO: 如果is_contract,编译期开启合约语法扩展检查 |
| 473 | if(!thinkyoung::lua::lib::compilefile_to_file(fname, out_fname.c_str(), error, use_type_check_compile)) |
| 474 | { |
| 475 | printf("compile %s error\n", fname); |
| 476 | if (strlen(error) > 0) |
| 477 | { |
| 478 | perror(error); |
| 479 | lua_set_compile_error(L, error); |
| 480 | } |
| 481 | return LUA_ERRRUN; |
| 482 | } |
| 483 | return thinkyoung::lua::lib::run_compiledfile(L, out_fname.c_str()) ? LUA_OK : LUA_ERRRUN; |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | static int run_decompile_script(lua_State *L, char **argv, int script) |
| 488 | { |
no test coverage detected