Page 1 of 1

How to communicate from .CELX script to ScriptedOrientation?

Posted: 09.06.2007, 19:49
by selden
How can I pass the value of an arbitrary variable from a .CELX script to a Lua module which is being used for a ScriptedOrientation?

I've wasted most of today trying to get Celestia to do this, but all of my attempts have failed. Presumably one needs to provide a method that both procedures can access, but I simply can't figure out a way to do that which works.

(I'm trying to pass a rotation angle to the Hubble orientation script so that its fov image can be properly oriented on the sky.)

Re: How to communicate from .CELX script to ScriptedOrientat

Posted: 09.06.2007, 21:18
by hank
selden wrote:How can I pass the value of an arbitrary variable from a .CELX script to a Lua module which is being used for a ScriptedOrientation?

I've wasted most of today trying to get Celestia to do this, but all of my attempts have failed. Presumably one needs to provide a method that both procedures can access, but I simply can't figure out a way to do that which works.

(I'm trying to pass a rotation angle to the Hubble orientation script so that its fov image can be properly oriented on the sky.)

I think the problem is that user scripts and ScriptedOrientation scripts run in separate Lua states, so they can't communicate directly. You would need a new celx built-in function to get around this.

- Hank

Posted: 09.06.2007, 22:23
by selden
That's what I was afraid of :(

Would it be possible to add such a capability? Presumably it'd need to be able to pass tables in both directions, for both ScriptedOrbits and ScriptedOrentations.

Posted: 09.06.2007, 23:04
by hank
selden wrote:That's what I was afraid of :(

Would it be possible to add such a capability? Presumably it'd need to be able to pass tables in both directions, for both ScriptedOrbits and ScriptedOrentations.

I was thinking of something along the lines of:

Code: Select all

celestia:setcommon(key,value);

and

Code: Select all

value = celestia:getcommon(key);


which could be called from any lua script running in Celestia. I think that might be possible to do.

- Hank

Posted: 09.06.2007, 23:09
by selden
Hank,

That certainly would do the job!

Although wouldn't it need some way to transmit the size of the data element? Or were you thinking it would always be a single 64 bit value?

Posted: 10.06.2007, 01:01
by hank
selden wrote:Hank,

That certainly would do the job!

Although wouldn't it need some way to transmit the size of the data element? Or were you thinking it would always be a single 64 bit value?

I think any lua value could be shared in this way, using the lua registry. The registry is a lua table that can be accessed by any lua function implemented in C. The celestia:setcommon() function would store the value in a subtable stored in the registry, from which the celestia:getcommon() function would retrieve it.

- Hank

Posted: 11.06.2007, 18:09
by chris
Scripts executed via the File menu, ScriptedOrbits/Rotations, and the Lua hook all run in separate Lua states. The exception is that ScriptedOrbits/Rotations run in the same Lua state if the ScriptSystemAccessPolicy is set to allow (since the Lua hook always has system access, it must run in a separate Lua state if ScriptedOrbits/Rotations aren't permitted system access.)

It should be possible to make ScriptedOrbits/Rotations and File menu scripts share a Lua state. At least, I can't think of a reason not to do this . . . It would break down like this:

ScriptSystemAccessPolicy=allow:
LuaHook, File menu scripts, ScriptedOrbit/Rotation all share a Lua state

ScriptSystemAccessPolicy=ask,deny:
LuaHook runs in unprotected Lua state
File menu scripts and ScriptedOrbit/Rotation run in sandboxed Lua state

--Chris

Posted: 11.06.2007, 18:15
by selden
Chris,

That sounds reasonable to me.