Skip to content

Commit b9879dd

Browse files
natecraddockNathan Craddock
authored andcommitted
Update pushLightUserdata to accept a const pointer
This makes the function more flexible. Should be safe because Lua doesn't modify the pointer. Closes #199
1 parent e61f111 commit b9879dd

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/lib.zig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,8 +2075,10 @@ pub const Lua = opaque {
20752075
/// * Lua Errors: `never`
20762076
///
20772077
/// See https://www.lua.org/manual/5.4/manual.html#lua_pushlightuserdata
2078-
pub fn pushLightUserdata(lua: *Lua, ptr: *anyopaque) void {
2079-
c.lua_pushlightuserdata(@as(*LuaState, @ptrCast(lua)), ptr);
2078+
pub fn pushLightUserdata(lua: *Lua, ptr: *const anyopaque) void {
2079+
// Use @constCast and a *const anyopaque to allow this function to accept constant pointers. Lua doesn't ever modify
2080+
// the pointer so this should be safe, and makes pushLightUserdata more flexible.
2081+
c.lua_pushlightuserdata(@as(*LuaState, @ptrCast(lua)), @constCast(ptr));
20802082
}
20812083

20822084
/// Pushes the string pointed to by `str` onto the stack. Lua will make or reuse an internal copy of the given

0 commit comments

Comments
 (0)