12345678910111213141516171819202122232425262728293031323334353637383940 |
- <script src="../dist/skulpt.min.js" type="text/javascript"></script>
- <script type="text/javascript">
- function outf(text)
- {
- var output = document.getElementById("output");
- text = text.replace(/</g, '<');
- output.innerHTML = output.innerHTML + text;
- }
- function runit()
- {
- var prog = document.getElementById("code").value;
- var output = document.getElementById("output");
- output.innerHTML = '';
- Sk.configure({output:outf});
- try {
- var module = Sk.importMainWithBody("<stdin>", false, prog);
- var obj = module.tp$getattr('a');
- var runMethod = obj.tp$getattr('run');
- var ret = Sk.misceval.callsim(runMethod, 10);
- alert(ret.v);
- } catch (e) {
- alert(e);
- }
- }
- </script>
- <form>
- <textarea id="code" rows="24" cols="80">
- class Test:
- def run(self, b):
- self.a = 10 + b
- return self.a
- print "Hello World"
- a = Test()
- </textarea><br>
- <button onclick="runit()" type="button">Run</button>
- </form>
- <pre id="output"></pre>
|