RunScript.hx 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using StringTools;
  2. function isLua5_1() {
  3. final proc = new sys.io.Process("lua", ["-v"]);
  4. final out = proc.stderr.readLine();
  5. proc.close();
  6. return out.startsWith("Lua 5.1.");
  7. }
  8. function matchesExpectedMessage(actual:String) {
  9. // lua 5.1 doesn't print custom error objects
  10. if (actual == "(error object is not a string)") {
  11. return true;
  12. }
  13. return new EReg(Sys.args()[1], "").match(actual);
  14. }
  15. function main() {
  16. final proc = new sys.io.Process("lua", [Sys.args()[0]]);
  17. // ignore "lua: "
  18. final exceptionMessage = proc.stderr.readLine().substr(5);
  19. final hasExpectedMessage = matchesExpectedMessage(exceptionMessage);
  20. // we don't want a bare error without a stack trace
  21. final hasStackTrace = try {
  22. proc.stderr.readLine().contains('stack traceback');
  23. } catch (_:haxe.io.Eof) {
  24. false;
  25. };
  26. Sys.println('Error code: ${proc.exitCode()}');
  27. Sys.println('Has expected exception message: ${hasExpectedMessage}');
  28. // 5.1 interpreter doesn't handle custom objects
  29. Sys.println('Has call stack: ${hasStackTrace || isLua5_1()}');
  30. proc.close();
  31. }