lua-users home
lua-l archive

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


> 1. I think it is invalid for a C function to amend the stack beyond
> what it is given to it - but I see that there is only an assert to
> this effect which obviously is an optional check. My question is why
> is this check an assert and not something stronger like a runtime
> check?

(I am not sure I understood your concept of "stronger", but anyway...)

C is a different world from Lua. Almost anything can go very wrong, and
most of these things are uncheckable. For instance, there is no way to
check that a lua_State passed as the first argument to any API function
has not been closed. Moreover, we assume that C code in Lua libraries
are more stable and more well tested than regular Lua code. In the end,
we think it is not worth to pay a performance price for this somewhat
"illusion" of safety.

> 

> 2. Functions like luax_move() that copy stack values - are there use
> cases where such functions could amend the values in local variables
> of a Lua function? I take it that the Debug API would allow this to
> happen - but is there any other scenario where this can happen?

No. Only the debug API can interfere with other function's stuff.


> 3. Is it the case that all other APIs go via the core API in lapi.c,
> so that if I focus on this then it will resolve any issues with the
> rest of the APIs?

All API go via the core API, but not all the core API is in lapi.c.
There are a few functions in ldo.c and some in ldebug.c. **All are
clearly marked with *LUA_API***. No function without a LUA_API should
ever be called from outside the core. (No function with a LUA_API
should ever be called from inside the core, too; this rule is being
broken sometimes, but in very controled ways ;-) Anyway, it does not
concern us here.).

-- Roberto