This makes the api work for all versions of Lua. If Luau users wish to
set the debugname for the function, they can use the pushFunctionNamed
and pushClosureNamed functions.
Adds the latest release of LuaJIT v2.1 and all necessary build file
changes to build as a static library.
This has only been tested on aarch64 macos. Many LuaJIT flags are
missing from the build config. Even if it works, it may not be working
perfectly.
Uses the Lua 51 library bindings, so some additional LuaJIT functions
may be missing. These will be audited and added at a later time.
Part of #19
Luau does not support loading native compiled modules. This adds a panic
at build time if lang == .luau and shared = true.
Also removes exportFn from the Luau module.
Adds a function to return the Zig allocator associated with a Lua state.
The function will fail if the Lua state was not created with a Zig
allocator, or using the returned Allocator will segfault.
Correct use of this function is trusted to the programmer. Though in the
normal/default use of Ziglua, this will always be safe.
Closes#40
The Lua VM uses a void pointer to store some user data that is passed to
the custom allocator function.
This modifies Ziglua to require a pointer to be passed to the library
rather than allocating the pointer internally. This is primarily
motivated by clarity. This way makes it obvious that Ziglua diverges
form the norm in Zig code and requires a pointer to an allocator.
An additional benefit is the lua.allocator field is no longer required.
This makes the struct smaller, and removes confusion (why is
lua.allocator not always set?).
Part of #40
Namecall is a mechanism in Luau to speed up method invocations.
The basic idea is that the VM can cache method names (strings)
to integer indices the first time it executes a method call.
At this point it calls the "user atom callback" with the string.
The user callback is responsible for mapping the method string
to a unique 16-bit index that's returned to the VM.
Next time the VM encounters the same string, it already knows
how to map the string to an index as, so it will reuse the user's
16-bit index.
The above is the mechanism for quickly resolving function name
strings to integers. The other part of the API is using the
indices. This part is the __namecall function that's attached
to a (userdata) object's metatable. On a method call, the VM
knows that the userdata has a registered __namecall, and calls
that to dispatch to the actual user's native function to handle
the native method. The namecall dispatch routine uses lua.namecallAtom()
to retrieve the method name/index, which is used to select which
actual native method is called.
It's not very simple but it should be fast as the VM doesn't
need to do a string->function hash table lookup on every
method invocation.
I'm not 100% sure of the details, but I suspect that the VM may
also patch the bytecode (or some internal representation of it)
directly with the namecall indices rather than looking them up
from some string hash table.
After exposing compiler options as a module to the code, the doc build
was failing. It now needs to be part of the build.zig so the docs have
access to the config module.
Now the dependency.artifact("lua") includes the Lua headers so other
software (like LPeg for example) can link against the built Lua
artifact.
This also exposes the Luau headers, but those may not be as useful with
all of the changes. For example, there is no lauxlib.h header in Luau.
The Luau VM supports native f32 3- or 4-vectors so that typical
linear algebra operations are fast in game code.
Both the 3- and 4-vector flavors are supported. Use
-Dluau_vector_size=N to choose which. This must be configured
at build time, as the native Luau VM must be re-compiled for this
setting.
When I updated to the latest package manager APIs I removed the artifact
and header installation. It turns out there are some valid uses for
these. This exposes the artifact again. The headers will come later once
I figure things out.
Not sure if the top level config should be public. Then the use would be
ziglua.config.lang instead of ziglua.lang.
If build options grow this can be revisited.
Closes#44
Use the Zig package manager to download the sources for Lua 5.1 through
Lua 5.4. Luau still needs to be done this way.
The LuaVersion enum strings are changed to remove the _ characters, this
is a breaking change.
Also makes the tests rely on the module rather than the raw source file.
Not sure if this is a good idea yet, just testing some things.
This links the compiled lua library to the ziglua module so it doesn't
need to be linked manually in other projects.