ziglua icon indicating copy to clipboard operation
ziglua copied to clipboard

lua_53 is missing registerFns that's present in lua_51 and luau

Open nurpax opened this issue 6 months ago • 3 comments

what the title says

nurpax avatar Jan 08 '24 22:01 nurpax

registerFns is equivalent to luaL_register. This function does exist in Lua 5.2 and 5.3, but only with the compatibility module defined.

From Lua 5.2 and on, the replacement function is luaL_newlib.

The semantics of the functions are different though. The register function can optionally assign all of the functions to a name that is then registered in the global package table.

The newlib function only adds the functions to a table. It is the programmers job to do something with that table.

I'm not sure what should be done here. Because this is all in the "auxiliary" library, we could in theory introduce our own function that provides the same behavior to all versions of Lua.

natecraddock avatar Jan 12 '24 04:01 natecraddock

Oh, I didn't realize that. Actually I was using registerFns to do luaL_setfuncs. This is for registrating userdata object methods into the metatable. So that's the registerFns case where libname is null.

I guess adding an implementation of setFuncs from lib54.zig would be a good choice for Luau.

nurpax avatar Jan 12 '24 17:01 nurpax

I just realized this is at least partially resolved as of https://github.com/natecraddock/ziglua/pull/54.

I just tested and setFuncs now works fine in all versions of Lua. newLib does not work yet, but it is an easy fix if that is the case.

Now that all the lib files are combined I'm going to spend some time polishing the docs. https://github.com/natecraddock/ziglua/issues/25 I'll take another look at this when I do a pass on the registration functions and see if there is anything more to be done here

natecraddock avatar Mar 22 '24 04:03 natecraddock