Page 1 of 1

Lua-Hooks and wait()'s

Posted: 13.10.2012, 22:38
by Chuft-Captain
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

Re: Lua-Hooks and wait()'s

Posted: 13.10.2012, 23:07
by Cham
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.

Re: Lua-Hooks and wait()'s

Posted: 15.10.2012, 05:55
by Chuft-Captain
Thanks for confirming that Cham, but that is bad news.

Re: Lua-Hooks and wait()'s

Posted: 16.10.2012, 16:38
by jogad
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: