Custom class in Xojoscript

Hi,

I created a class for a complex mathematical object (called quaternion). I was thinking of trying to use this class in Xojoscript, which should be possible by setting the context.

However the simple class initialization “Dim q As New Quaternion” leads to an exception. On the other hand if Xojoscript is sandboxed how can it handle pointers? I am confused…What am I missing?

Thanks.

[quote=217002:@Davide Pagano]Hi,

I created a class for a complex mathematical object (called quaternion). I was thinking of trying to use this class in Xojoscript, which should be possible by setting the context.

However the simple class initialization “Dim q As New Quaternion” leads to an exception. On the other hand if Xojoscript is sandboxed how can it handle pointers? I am confused…What am I missing?

Thanks.[/quote]
You would need to create the quaternion class within XojoScript. You can use a XojoScript context to interact code within the sandbox directly to methods which you have written within the Xojo IDE.

So you can either write a clone of the class in XojoScript from scratch or you can write the class and use methods as a wrapper.

http://documentation.xojo.com/index.php/XojoScript.Context

Sounds like an interesting project Davide. May I ask what you are going to use the the quaternion class for?

[quote=217004:@Oliver Scott-Brown]You would need to create the quaternion class within XojoScript. You can use a XojoScript context to interact code within the sandbox directly to methods which you have written within the Xojo IDE.

So you can either write a clone of the class in XojoScript from scratch or you can write the class and use methods as a wrapper.
[/quote]

I don’t undestand. I have already set the the context of the xojoscript to an instance of my class. Should’t it be enough?

In my spare time I am working on an application for data analysis and manipulation. As quaternions have many applications in Physics (I am Physicist) and Mathematics I thought it could be fun to try to include them in this project…also because there aren’t many applications can handle them out there…

By reading the documentation I think I found the reason why it cannot work:

<<Any methods or properties that use objects will not be allowed within the script.>>

In Xojo Script you can define classes but you cant pass an instance of them across the context
Nor can you access classes defined in your Xojo code directly in XojoScript

The CONTEXT is a boundary that you can’t pass instances across

[quote=217011:@Davide Pagano]I don’t undestand. I have already set the the context of the xojoscript to an instance of my class. Should’t it be enough?

In my spare time I am working on an application for data analysis and manipulation. As quaternions have many applications in Physics (I am Physicist) and Mathematics I thought it could be fun to try to include them in this project…also because there aren’t many applications can handle them out there…[/quote]
I think your best option is probably to write the class in XojoScript. But you can use the context like this for example (as pseudo code).

method newQuaternion {
quaternionModule.Quaternions.Append (new Quaternion)
}

method getQuaternionZ returns double {
return quaternionModule.Quaternions(index).z
}

method setQuaternionZ (value) {
quaternionModule.Quaternions(index).z = value
}

You could also maybe use introspection and create a method with a name like getQuaternionProperty. You would then pass a string in which would sort of give you direct and automatic access to the properties.

http://documentation.xojo.com/index.php/Introspection