Skip to content

Use zig assert for apicheck#213

Open
natecraddock wants to merge 4 commits into
mainfrom
apicheck
Open

Use zig assert for apicheck#213
natecraddock wants to merge 4 commits into
mainfrom
apicheck

Conversation

@natecraddock
Copy link
Copy Markdown
Owner

Using a zig assert for apicheck enables stack traces for panics.

TODO:

  • Lua 5.5 changed how LUA_USE_APICHECK works and I cannot find a way to define lua_assert correctly
  • Not working for luajit yet. Haven't looked closely

Instead of only enabling api check in debug builds, expose an option to
* enable apicheck
* disable apicheck
* enable in debug builds

This gives users more control.
Move it to the base build file
Luajit also supports apicheck.

Enabling uncovered an error in opening the bit32 library which is fixed
by using call().
@natecraddock natecraddock linked an issue May 10, 2026 that may be closed by this pull request
@natecraddock
Copy link
Copy Markdown
Owner Author

It's looking like it might not be possible to get this working in Lua 5.5 currently.

Other versions of Lua work like this:

  1. The user.h file creates this define #define luai_apicheck(l,e) zlua_assert(e)
  2. luai_apicheck is later used in the definition of lua_assert

Lua 5.5 removed luai_apicheck. If you try to define lua_assert in the user h file, a later import from lapi.h unconditionally defines lua_assert which overrides the custom one from the user h file.

I tried patching the lapi.h header file to remove those definitions, but since headers are searched for in directories I couldn't find a way to exclude the original unpatched lapi.h. Maybe copy all of the other headers and the patched header to a new directory?

I'm considering posting on the Lua mailing list about this change in behavior in Lua 5.5 and see what comes up

@robbielyman
Copy link
Copy Markdown
Collaborator

robbielyman commented May 11, 2026

@natecraddock looking through the source, I suspect one can do

#undefine LUA_USE_APICHECK
#define api_check(l,e,msg)     zlua_assert(l,e,msg)

hmmm... apparently not...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Define apicheck function to use a Zig panic

2 participants