lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello Diego,

>> Actually never mind, I think I have it working. I passed the wrong
>> number of arguments to newthread and it crashed my app. I guess it
>> doesn't use a pcall...

> Which function? thread.newthread from LuaThread? If you call that with
> extra arguments, they are ignored. If you call withtout the argument
> table, it barks at you. What do you mean it crashed?

actually thread_entry, it uses lua_call. Thus if there is some kind of
error like calling a function that does not exists it exists the app.
I modified this code to be a pcall. That way I can gracefully handle
the error and print the error message.

>> Should I protect the Lua functions in Delphi in some way or are things
>> ready to go without changes?

> Didn't understand this question either. :/

Sorry about. What I am trying to find out is if C-functions that have
been exported to lua have to take special precautions when using the
lua api. Here is an example of fake code to illustrate my question:

// c code.
int lua_call_calc(lua_State *L) // exported as call_calc
{
 lua_getglobal(L,"calc");
 lua_getglobal(L,"a");
 lua_getglobal(L,"b");
 lua_call(L,2,1);
 lua_setglobal(L,"x");
 return 0;
}

int lua_call_boo(lua_State *L)   // exported as call_boo
{
 lua_getglobal(L,"boo");
 lua_getglobal(L,"y");
 lua_getglobal(L,"q");
 lua_call(L,2,1);
 lua_setglobal(L,"x");
 return 0;
}

// lua code:
function t1 (o)
  for i=0,100 do
    call_boo()
  end
end

function t2(o)
  for i=0,100 do
    call_calc()
  end
end

thread.newthread(t1, {1} )
thread.newthread(t2, {2} )


I could see some funny stuff happening if 2 functions
start messing with the stack at the same time. Do we need to grab a
mutex before we do this? How is the Lua stack protected?

- Ron