Thursday, 9 September 2010

(Iron)Python is dead, long live the Boo

We use Lua for scripting for some time (for more than an year for now) and what's good about lua is that is easy to be embedded, is fast, have low memory requirements, and so on.
On the other hand, Lua have its own problems when is about unit testing. In fact we have testing that are written in Lua. They mostly test the shape creation with fixed arguments that scripting integration provides. So most probably, as if you create more scripts in Lua, you will have a stable NaroCAD at least on shape creation side.
Anyway, for some time, most of problems were in cases that shapes do not get right arguments, not the cases that they get good ones. For example: if an user inputs a zero value on sphere range, it may happen that Lua's corresponding function to not crash, the same about opencascade function that create this shape, but property grid, solver component may crash as they extract themselves (in cascade) the very same (invalid) shape.
It would be great that some testing to be able to be done inside NaroCAD and to be high level testing, not low level one (that can be covered by Lua). So I've extended a bit the capabilities of importing plugins so they can run at startup. Another part is that I've removed from Debug builds a live debugging window and I've moved in this same plugin.
Also, I've integrated Boo console scripting in this plugin to be a remote to launch custom NaroCAD code.

Why Boo? Firstly, because is not a dead project, as are IronRuby and IronPython.
Another reason, is that have a documented way how to integrate both the compiler and interpreter. This makes to integrate with this code as a breeze. A very important part is that is a static typed .NET language implementation, like C# and VB.NET, meaning that if I give the right object, will have all methods working. This makes that after integration is done, I simply look to an object Test and I execute method RunTest directly.
But what about a person wanting to write his own test, he knows C#, but he doesn't know Boo or (Iron)Python to write this code? The very easy solution is to download SharpDevelop, and if you open NaroCAD in it, go to the a C# file where you have the code, under Tools > Convert Code To > Boo and voila, you have the coding.

I've made three small code samples: one that simply execute something without being NaroCAD related (Hello world sample), another that switch the view to Left view, the very last, shown below, will create a line (in NaroCAD framework) and will write text to command line that will build a line.

import NaroPipes.Actions from NaroPipes
import NaroPipes.Constrants
import Naro.Infrastructure.Interface.Constants from Infrastructure.Interface

class Test:
_actionsGraph as ActionsGraph

def SendCommandLineText(message as string):
commandLineInput = _actionsGraph.InputContainer.Inputs[InputNames.CommandLineView]

def RunTest(actionsGraph as ActionsGraph):
_actionsGraph = actionsGraph
SendCommandLineText("100, 100, 0");
SendCommandLineText("100, 200, 0");

No comments:

Post a Comment