How to communicate from .CELX script to ScriptedOrientation?

All about writing scripts for Celestia in Lua and the .cel system
Avatar
Topic author
selden
Developer
Posts: 10192
Joined: 04.09.2002
With us: 22 years 2 months
Location: NY, USA

How to communicate from .CELX script to ScriptedOrientation?

Post #1by selden » 09.06.2007, 19:49

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.)
Selden

hank
Developer
Posts: 645
Joined: 03.02.2002
With us: 22 years 9 months
Location: Seattle, WA USA

Re: How to communicate from .CELX script to ScriptedOrientat

Post #2by hank » 09.06.2007, 21:18

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

Avatar
Topic author
selden
Developer
Posts: 10192
Joined: 04.09.2002
With us: 22 years 2 months
Location: NY, USA

Post #3by selden » 09.06.2007, 22:23

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.
Selden

hank
Developer
Posts: 645
Joined: 03.02.2002
With us: 22 years 9 months
Location: Seattle, WA USA

Post #4by hank » 09.06.2007, 23:04

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

Avatar
Topic author
selden
Developer
Posts: 10192
Joined: 04.09.2002
With us: 22 years 2 months
Location: NY, USA

Post #5by selden » 09.06.2007, 23:09

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?
Selden

hank
Developer
Posts: 645
Joined: 03.02.2002
With us: 22 years 9 months
Location: Seattle, WA USA

Post #6by hank » 10.06.2007, 01:01

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

chris
Site Admin
Posts: 4211
Joined: 28.01.2002
With us: 22 years 9 months
Location: Seattle, Washington, USA

Post #7by chris » 11.06.2007, 18:09

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

Avatar
Topic author
selden
Developer
Posts: 10192
Joined: 04.09.2002
With us: 22 years 2 months
Location: NY, USA

Post #8by selden » 11.06.2007, 18:15

Chris,

That sounds reasonable to me.
Selden


Return to “Scripting”