500 if(typeof(document) == "object") |
500 if(typeof(document) == "object") |
501 print = function (a) { document.write(a+"<br/>") }; // Browser |
501 print = function (a) { document.write(a+"<br/>") }; // Browser |
502 else |
502 else |
503 print = require("sys").puts; // Nodejs |
503 print = require("sys").puts; // Nodejs |
504 |
504 |
505 default_environment.setIndex(LValueFromString("print"), LValueFromFunction(print)); |
505 var mt = new LValue("table", {}); |
|
506 mt.setIndex( |
|
507 LValueFromString("__index"), |
|
508 LValueFromFunction(testvm, function (t, k) { sys.puts("Access of nil global: "+k); }) |
|
509 ); |
|
510 default_environment.setMetatable(mt); |
|
511 default_environment.setIndex(LValueFromString("print"), LValueFromFunction(testvm, print)); |
506 |
512 |
507 var f = new LFunction(testvm, c, default_environment); |
513 var f = new LFunction(testvm, c, default_environment); |
508 |
514 |
509 try{ |
515 try{ |
510 var ret = testvm.call(f); |
516 var ret = testvm.call(f); |