Skip to content

Make Lua an opqaque#73

Merged
natecraddock merged 1 commit intomainfrom
opaque
Mar 23, 2024
Merged

Make Lua an opqaque#73
natecraddock merged 1 commit intomainfrom
opaque

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.
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