[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: C API const correctness
- From: Roberto Ierusalimschy <roberto@...>
- Date: Fri, 06 Oct 2000 12:40:53 -0300
> It would be nice if someday the C API was made const correct. I'm referring
> to the lua_State argument of all the API functions. If a function does not
> affect the state, the state pointer argument should be qualified as const.
The problem is that there is a difference between a "function that does
not change the struct lua_State" and a "function that does not affect the
state seen through the API". The `struct lua_State' being const in the eyes
of the C compiler is too implementation dependent, and so it is not a good
idea to export such details to the API.
For instance, in the current implementation, the `lua_insert' function
(that changes elements in the stack) could be declared const, while
lua_getn (that only returns the size of an array) could not. (The first one
changes only the stack, but not its size, so lua_State is constant. The
second may need to create a string, an therefore can potentially resize
some internal structures, changing lua_State).
-- Roberto