Lua-Hooks and wait()'s

All about writing scripts for Celestia in Lua and the .cel system
Avatar
Topic author
Chuft-Captain
Posts: 1779
Joined: 18.12.2005
With us: 18 years 4 months

Lua-Hooks and wait()'s

Post #1by Chuft-Captain » 13.10.2012, 22:38

The issue is:

I have a celX script which takes a reasonable period of time (a few seconds or more) to execute.... long enough that I have included periodic wait()'s in order to return control to Celestia within the ~ 5 sec limit.

This is all good and works OK if the script is called directly from Celestia,...
... but when there is a Lua-Hook involved (eg. the script is called from LuaEduTools), the wait() appears to cause the following error:

Code: Select all

"attempt to yield across metamethod/C-call boundary"


If I remove the wait(), this error doesn't occur, but instead I get:

Code: Select all

Timeout: script hasn't returned control to celestia (forgot to call wait()?)
Error while executing Lua Hook: Timeout: script hasn't returned control to celestia (forgot to call wait()?)


Is there a way to handle wait()'s when a LuaHook is involved, if so, does anyone know what the trick is to getting this to work?

Or, is it just not possible in the context of a LuaHook?

Cheers
CC
"Is a planetary surface the right place for an expanding technological civilization?"
-- Gerard K. O'Neill (1969)

CATALOG SYNTAX HIGHLIGHTING TOOLS LAGRANGE POINTS

Avatar
Cham M
Posts: 4324
Joined: 14.01.2004
Age: 59
With us: 20 years 3 months
Location: Montreal

Re: Lua-Hooks and wait()'s

Post #2by Cham » 13.10.2012, 23:07

This is a known bug. I can't tell where it is located, but I already experienced something like this with some of my own celx scripts before.

Vincent is the expert in LUA and CELX.
"Well! I've often seen a cat without a grin", thought Alice; "but a grin without a cat! It's the most curious thing I ever saw in all my life!"

Avatar
Topic author
Chuft-Captain
Posts: 1779
Joined: 18.12.2005
With us: 18 years 4 months

Re: Lua-Hooks and wait()'s

Post #3by Chuft-Captain » 15.10.2012, 05:55

Thanks for confirming that Cham, but that is bad news.
"Is a planetary surface the right place for an expanding technological civilization?"
-- Gerard K. O'Neill (1969)

CATALOG SYNTAX HIGHLIGHTING TOOLS LAGRANGE POINTS

Avatar
jogad
Posts: 458
Joined: 17.09.2008
With us: 15 years 7 months
Location: Paris France

Re: Lua-Hooks and wait()'s

Post #4by jogad » 16.10.2012, 16:38

Hi,

Wait is not allowed but the control returns to celestia each time a window is drawn.
You have to dispach your procedure in a .Customdraw function.

Ex

Code: Select all

maxtex = 20
for tex = 1, maxtex do
   picture[tex]=celestia:loadtexture(texture[tex])
end

If your maxtex is too big you have a timeout error. (I had this for loading my multicockpits textures).

Here is a workaround :

Code: Select all

tex = 0 -- or whatever value out of the interval 1..maxtex

Frame.Customdraw = function()
   if tex >= 1 and text <= maxtex then
      picture[tex]=celestia:loadtexture(texture[tex])
      tex = tex + 1
   end
end

calling_function = function()
   tex = 1
   maxtex = 20
end


This works only if the Frame is visible.
For example, the main frame of the script is always visible.

Hope this help.
:mrgreen:


Return to “Scripting”