Last modified 9 months ago
Last modified on 09/01/11 16:14:58
Scripting
Ideas about scripting in GeoGebra at the International GeoGebra Conference 2011.
Goal
Scripting should be simple for simple tasks, but more advanced users need (and can be bothered) with more advanced techniques and scripting languages.
Different Scripting Systems
- GeoGebraScript: Good for simple scripts (no loops, no conditionals), intended for immediate users
- JavaScript: Good for more complex scripts, intended for advanced users
- Python: Needs additional setup (ie can't be part of GeoGebra), similar to JavaScript for users who prefer Python over JavaScript
Current Situation
- GeoGebraScript is good as it is at the moment and purpose, but JavaScript is far too difficult to use in combination with GeoGebra to solve real-life problems at the moment.
- There is a gap between GeoGebraScript, which is easy to use to execute GeoGebra commands but lacks program control structures, and JavaScript, which has some powerful features to control the flow of the program but is extremely cumbersome to use to execute GeoGebra commands and to communicate with GeoGebra in general.
Idea
- Keep GeoGebraScript, enhance JavaScript (convert old scripts to new script automatically)
- Starting with Java 6 there is a scripting engine, which supports JavaScript out of the box (ie no additional library) and provides a common interface for other scripting languages (e.g. Python).
- It is closely coupled to Java classes, so a simplified interface of GeoGebra (ie GeoElements) could be provided for object-oriented scripting.
- Add native listeners to GeoElements to listen for clicks, updates, changes, etc.
Syntax
- Use $.varname to reference to a GeoGebra object called 'varname'
- Use $ A = (1, 0) to evaluate a GeoGebra command
- Use # to indicate a scripting expression in a GeoGebra command as demonstrated below
Example
var num = 2; $ points = Sequence[(i, 2*i), i, #2*num#, 10] $.points.setVisible(false); var list = $.points; list.setVisible(true); list.addObjectListener(...);
Advantages
- Close coupling between GeoGebra and Java scripting engine.
- No external scripting engine required to be loaded (already part of JRE).
- Same scripting support for both applets and the application.
Disadvantages
- Requires Java 6.
- Harder to integrate into GeoGebraMobile as we can't use the browser directly to parse the JavaScript code but have to convert the Java -> JavaScript interface to JavaScript first (but as we do JavaScript scripting in a JavaScript application it should be not too hard).
Open Problems
- How to integrate this scripting capabilities into GeoGebraMobile (just JavaScript for scripting there).
- How to use Python for scripting? Using Python for scripting makes file incompatible with the normal GeoGebra version, so it's just for users who know what they do (and who probably do their own stuff).
References
- Rhino reference (JavaScript, modified version used in Java JRE): http://www.mozilla.org/rhino/ScriptingJava.html
- Jython: http://szyzygycode.wordpress.com/2010/03/03/embedding-jython-script-in-java-with-scriptengine/
Attachments
- GeoGebra Scripting Prototype.zip (2.3 KB) - added by florian 9 months ago.
