Re: [Xswt-developer] scripting
Brought to you by:
dvorme
|
From: <ha...@id...> - 2006-06-16 22:13:20
|
> -----Original Message----- > 1. Re: scripting (David J. Orme) > > I've downloaded and been gradually working through your > thesis. It looks cool, but it's not light reading either. :-) No, but I guess you can skip some chapter, i.e. focus on Diamodl. A video demo is available at http://www.idi.ntnu.no/~hal/publications/diamodl-editor/cadui-demo.html and a rejected demo paper at http://www.idi.ntnu.no/~hal/publications/diamodl-editor/cadui-demo-2006-reje cted.pdf (mostly due to overlap with an accepted paper). > > The design I'm aiming for, should let the specific scripting language > > decide how scripts are separated from each other, using the language's > > own modularisation mechanism, e.g. pnuts' packages. A scripting > > language extension may also decide to not support modularisation and > > refer to x:ids directly. > > > This sounds sensible, but I think we should eventually > publish some kind of recommendation about how to do this so > that we don't wind up with widely diverging implementations. Below I've included an XSWT file I made earlier today, that implements a simple calculator with XSWT and pnuts scripting. It works on my version of XSWT + the pnuts extension, which will be committed fairly soon. It gives an impression of the current design. I've deliberately split the script into parts, to test the modularisation mechanism. The package prefix clutters the code somewhat, but it makes it easier to see how one script uses the other. > Or have I completely misunderstood (e.g. the IDataParsers > > may be part of the runtime)? > > > No, there's a separate set of objects--the ICodeGenerator > interface and its implementations that handle this sort of thing. OK, I'll try to see if I understand it. > I'm slowly but surely making progress on the XSWT Builder. I can't wait to see it. Hallvard ----8<------------- <?xml version="1.0" encoding="UTF-8"?> <xswt xmlns:x="http://sweet_swt.sf.net/xswt"> <x:import> <package name="java.lang"/> <package name="org.eclipse.swt.widgets"/> <package name="com.swtworkbench.community.xswt.scripting"/> <package name="org.eclipse.swt.layout"/> </x:import> <composite> <layout x:class="gridLayout" numColumns="5"/> <script x:id="math" lang="pnuts"> function plus (n1, n2) n1 + n2 function minus(n1, n2) n1 - n2 function mult (n1, n2) n1 * n2 function div (n1, n2) n1 / n2 </script> <text x:id="result" text=" 0"> <layoutData x:class="gridData" horizontalSpan="5" horizontalAlignment="FILL" grabExcessHorizontalSpace="true"/> </text> <script x:id="calc" lang="pnuts"> n1 = 0; n2 = null; mem = 0; op = null; function setOp(op) { setN1(); if (op == "-") { calc::op = math::minus; } else if (op == "+") { calc::op = math::plus; } else if (op == "*") { calc::op = math::mult; } else if (op == "/") { calc::op = math::div; } else { calc::op = op; } calc::n2 = ""; } function getN(n) { int(n); } function updateDigits() { digits = if (calc::n2 instanceof String) calc::n2 else calc::n1; id::result.text = "" + digits; // id::result.text = "" + (if (calc::n1 instanceof String) "\"" else "") + calc::n1 + ":" + (if (calc::n2 instanceof String) "\"" else "") + calc::n2 + ":" + calc::op; } function appendDigit(d) { if (calc::n2 instanceof String) { calc::n2 = calc::n2 + d; } else if (calc::n1 instanceof String) { calc::n1 = calc::n1 + d; } else { calc::n1 = "" + d; } updateDigits(); } function setN1(n) { calc::n1 = n; calc::n2 = null; calc::op = null; n } function setN1() setN1(getN(calc::n1)); function setN2(n) { calc::n2 = n; n } function setN2() setN2(getN(calc::n2)); function calculate() { if (calc::op != null) { setN2(); setN1(calc::op(calc::n1, calc::n2)); } updateDigits(); } function setMem(n) calc::mem = n </script> <button text="MC" selectionListener="handlers.memClear"/> <button text="7" selectionListener="handlers.digit"/> <button text="8" selectionListener="handlers.digit"/> <button text="9" selectionListener="handlers.digit"/> <button text="/" selectionListener="handlers.op"/> <button text="MR" selectionListener="handlers.memRecall"/> <button text="4" selectionListener="handlers.digit"/> <button text="5" selectionListener="handlers.digit"/> <button text="6" selectionListener="handlers.digit"/> <button text="*" selectionListener="handlers.op"/> <button text="M+" selectionListener="handlers.memPlus"/> <button text="1" selectionListener="handlers.digit"/> <button text="2" selectionListener="handlers.digit"/> <button text="3" selectionListener="handlers.digit"/> <button text="-" selectionListener="handlers.op"/> <button text="C" selectionListener="handlers.clear"/> <button text="0" selectionListener="handlers.digit"/> <button text=","/> <button text="=" selectionListener="handlers.calc"/> <button text="+" selectionListener="handlers.op"/> <script x:id="handlers" lang="pnuts"> function digit(event) calc::appendDigit(event.widget.text); function op(event) calc::setOp(event.widget.text); function clear(event) { calc::setN1(0); calc::updateDigits(); } function memClear(event) calc::setMem(0); function memRecall(event) calc::setN1(calc::mem); function memPlus(event) calc::setMem(calc::mem + calc::setN1()); function calc(event) calc::calculate(); </script> </composite> </xswt> |