It is currently Thu, 21-06-18, 19:33 GMT

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: CelX from LUA
PostPosted: Fri, 29-08-14, 9:00 GMT 
Offline
User avatar

Joined: Fri, 03-04-09, 8:21 GMT
Posts: 219
Hi,

Does anyone know if there's any way to call CELX commands from a .lua file?

eg. celestia:gettime(), position:vectorto(...)

Cheers
CC

_________________
CITIZENS OF CM - JOIN THE REVOLUTION
...black out your avatar
THE AVATARS ARE REVOLTING !!!


Top
 Profile  
 
 Post subject: Re: CelX from LUA
PostPosted: Fri, 29-08-14, 12:04 GMT 
Offline
User avatar

Joined: Mon, 03-09-07, 23:01 GMT
Posts: 417
Location: Tuscany, Tyrrhenian Sea
Do you mean how CELX commands are declared within a .lua file?

_________________
Never at rest.
Massimo


Top
 Profile  
 
 Post subject: Re: CelX from LUA
PostPosted: Fri, 29-08-14, 14:26 GMT 
Offline
User avatar

Joined: Fri, 03-04-09, 8:21 GMT
Posts: 219
No, well sort of....

I mean: "how (if it's possible at all) do you call CELX commands from LUA?"

eg. If you have declared a LUA function in file A.lua, and you want to call it from B.lua, you just need to "include" the file A in file B, like so....

eg. A.lua :
Code:
helloworld = function()
print("Hello World")
end
B.lua :
Code:
require "A"

helloworld()


That's fine when dealing with LUA libraries, however I want to call CELX methods from a LUA file.
eg.

require "A"
helloworld()
print("The simulation time is:"..celestia:gettime() )
[/code]

Calling a CELX method from a LUA file in this fashion, causes a crash at startup.
Adding a require stmt like:
Code:
require "celestia"
.. (a shot in the dark) ... seems to prevent the crash, but doesn't appear to work as it prevents execution of the LUA code (it's obviously not a valid statement).

One of the DEV's will likely know, or at least be able to examine the code to see if this is possible, and if so what are the necessary "require" modules (assuming that's the mechanism).

There are many very useful CELX commands, and I would like to be able to call some of them from a scriptedorbit function (necessarily declared in a .LUA file), however there may be a number of reasons such as loss of context, which would make this impossible, or at the very least dangerous to do.

Regards
CC

PS. Come to think of it, I've had no problems using celestia:log() to debug scriptedorbit functions, so it's clearly possible to access some CELX functions under certain circumstances in LUA.

...Maybe the crash was just specific to the context in which I was calling celestia:gettime()

I'll have to re-examine this...

_________________
CITIZENS OF CM - JOIN THE REVOLUTION
...black out your avatar
THE AVATARS ARE REVOLTING !!!


Last edited by chuft-captain on Fri, 29-08-14, 14:48 GMT, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: CelX from LUA
PostPosted: Fri, 29-08-14, 14:41 GMT 
Offline
User avatar

Joined: Mon, 03-09-07, 23:01 GMT
Posts: 417
Location: Tuscany, Tyrrhenian Sea
e.g A.lua:
Code:
helloworld = function()
local p = "The simulation time is:"
return p
end

then:
B.lua:
Code:
require "A"
local p = helloworld()
local t = celestia:gettime()
celestia:print(p.." "..t, 2)

if you want the CELX COMMAND to print on screen; that is not "print" but "celestia:print". The declarion for CELX COMMAND are those with the prefix "celestia:".

_________________
Never at rest.
Massimo


Top
 Profile  
 
 Post subject: Re: CelX from LUA
PostPosted: Fri, 29-08-14, 14:59 GMT 
Offline
User avatar

Joined: Fri, 03-04-09, 8:21 GMT
Posts: 219
Sorry Fenerit,

The code snippits above were just for illustration purposes, but is not the actual code, so don't bother trying to solve that example. In fact, that code above may in fact work perfectly well.
I think it is something about the context in which I'm calling the gettime() which is quite different and involves a scriptedorbit (see my PS above).
There are some timing issues around the way that scriptedorbits are executed, so it's probably something to do with that.

The code is a little too complex to post, so I think I'll have to just try to debug it by myself.
Thanks for the effort though.

CC

_________________
CITIZENS OF CM - JOIN THE REVOLUTION
...black out your avatar
THE AVATARS ARE REVOLTING !!!


Top
 Profile  
 
 Post subject: Re: CelX from LUA
PostPosted: Fri, 29-08-14, 15:06 GMT 
Offline
User avatar

Joined: Mon, 03-09-07, 23:01 GMT
Posts: 417
Location: Tuscany, Tyrrhenian Sea
Ah, ok.

I can try to guess :o : celestia:gettime() must have a variable assigned?

_________________
Never at rest.
Massimo


Top
 Profile  
 
 Post subject: Re: CelX from LUA
PostPosted: Fri, 29-08-14, 15:13 GMT 
Offline
User avatar

Joined: Fri, 03-04-09, 8:21 GMT
Posts: 219
No, no.. nothing like that, but if you've ever used a scriptedorbit, you'll know that they are called many times per second in between frame renders, so that could potentially create some issues / challenges for celestia:gettime(). -- Something along these lines is what I suspect is the cause of the crash.

What I'm actually working on is a proof-of-concept using scripted-orbits to implement real world physics in Celestia. IMO, there's enough grunt in most modern CPU's to make this potentially feasible, at least in a limited form.

http://youtu.be/6aQC_9fyPE4

_________________
CITIZENS OF CM - JOIN THE REVOLUTION
...black out your avatar
THE AVATARS ARE REVOLTING !!!


Last edited by chuft-captain on Thu, 04-09-14, 12:05 GMT, edited 5 times in total.

Top
 Profile  
 
 Post subject: Re: CelX from LUA
PostPosted: Fri, 29-08-14, 15:23 GMT 
Offline
User avatar

Joined: Mon, 03-09-07, 23:01 GMT
Posts: 417
Location: Tuscany, Tyrrhenian Sea
Well... just to discuss, being in the dark about your code.

Do you call e.g. t = celestia:gettime() within a contest of t - 2451545.0? It is not the same, I'm sure you know that.

_________________
Never at rest.
Massimo


Top
 Profile  
 
 Post subject: Re: CelX from LUA
PostPosted: Fri, 29-08-14, 15:36 GMT 
Offline
User avatar

Joined: Fri, 03-04-09, 8:21 GMT
Posts: 219
Actually, I can probably get by without gettime()...

It's actually the capabilities of some of the position and vector functions, which would be most useful in this application...

_________________
CITIZENS OF CM - JOIN THE REVOLUTION
...black out your avatar
THE AVATARS ARE REVOLTING !!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group