lua-users home
lua-l archive

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


On Fri, May 22, 2020, at 21:06, Joseph C. Sible wrote:

> A lot of emphasis is placed on the fact that Lua bytecode runs on a
> register-based VM, rather than on a stack-based VM, and that this is
> significant for performance reasons. Why is the Lua C API then
> stack-based instead of also being register-based for the same reason?

The stack-based C API predates the register-based VM, which was only
introduced in Lua 5. The way I see it, the C API is an interface designed
for the user, and the use of registers internally (which are themselves
organized in a stack) is an implementation detail.

A "register-based API" would not be much different anyway, the main
alternative to the stack-based API used by Lua would be an "object"
API where pointers to internal objects are returned to the caller. This
kind of API is used in several other languages but it has a huge drawback
compared to what Lua does, which is that callers have to interact with the
GC. It makes it a lot more error-prone in practice.

-- 
Pierre Chapuis