test-io.nut 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. local line;
  2. while((line = stdin.read_line())) print(line);
  3. local str = "localhost:8080";
  4. local t = str.find(":");
  5. local host = str.substr(0, t);
  6. local port = str.substr(t+1);
  7. print(host, port);
  8. function format_test(text, err){
  9. local ret = "\n";
  10. local line_number = 1;
  11. local line_err = 0, line_str;
  12. err.gmatch(".*:(%d+):(.*)", function(err, str){
  13. line_err = err;
  14. line_str = str;
  15. return false;
  16. });
  17. foreach( line in text.split("\n")) {
  18. if (line_number == line_err.tointeger())
  19. ret += format("--> %d. %s (%s)\n", line_number, line, line_str);
  20. else
  21. ret += format("% 8d. %s\n", line_number, line);
  22. line_number = line_number + 1;
  23. }
  24. return ret;
  25. }
  26. function test(text){
  27. //compilestring(text)();
  28. try{
  29. print(34);
  30. print(35);
  31. //throw("In line " + __LINE__);
  32. compilestring(text)();
  33. }
  34. catch(e)
  35. {
  36. print(e);
  37. foreach(k, v in get_last_stackinfo()){
  38. print(k,v);
  39. }
  40. }
  41. local chunk = compilestring(text);
  42. if (chunk == null){
  43. print(format([==[
  44. ---------------------------------------------------------------
  45. %s
  46. loadstring error: '%s'
  47. ---------------------------------------------------------------
  48. ]==], format_test(text, err), err))
  49. return false;
  50. }
  51. try {
  52. chunk();
  53. }
  54. catch(e){
  55. print(format([==[
  56. ---------------------------------------------------------------
  57. %s
  58. call error: '%s'
  59. ---------------------------------------------------------------
  60. ]==], format_test(text, e), e));
  61. //return false;
  62. }
  63. return true;
  64. }
  65. test([==[
  66. local p = SqRs232();
  67. p.open("/dev/ttyS0");
  68. ]==]);
  69. print(23);