Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Lua an opqaque #73

Merged
merged 1 commit into from
Mar 23, 2024
Merged

Make Lua an opqaque #73

merged 1 commit into from
Mar 23, 2024

Conversation

natecraddock
Copy link
Owner

Rather than storing a *LuaState inside the Lua struct, this changes Lua to be an opaque type that directly represents the C lua_State.

Internally, this makes a few things slightly less readable. @ptrCast(lua) and @as(*LuaState, @ptrCast(lua)) are required when passing data to the c functions.

But externally, I think this makes more sense. The value returned from Lua.init() is always a pointer now, and is a direct pointer to the Lua state.

Overall this change is really subjective. There isn't a strong reason to go one way or the other, but I do think I slightly prefer using an opaque. It feels more "correct" to represent the opaque internal Lua state as a Zig opaque with associated methods.

@natecraddock natecraddock linked an issue Mar 22, 2024 that may be closed by this pull request
Rather than storing a *LuaState inside the Lua struct, this changes Lua
to be an opaque type that directly represents the memory passed to a Lua
struct.

Internally, this makes a few things slightly less readable.
@ptrCast(lua) and @as(*LuaState, @ptrCast(lua)) are required when
passing data to the c functions.

But externally, this makes more sense. The value returned from
Lua.init() is always a pointer now, and represents the Lua state itself.
@natecraddock natecraddock merged commit 4a5f946 into main Mar 23, 2024
3 checks passed
@natecraddock natecraddock deleted the opaque branch March 23, 2024 04:08
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.

Make the Lua struct an opaque
1 participant