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

luajit/lua51: fix loadFile and checkVersion #79

Closed
wants to merge 1 commit into from

Conversation

rockorager
Copy link

The luajit and lua51 internal API didn't take a mode variable, meaning
the function signature was different between these two versions and lua
5.2+. Add an unused Mode to the loadFile51 signature to allow building
with luajit/lua51

The checkVersion function calls luaL_checkversion, which was only
introduced in lua 5.2. Add an empty call when using a version less than
5.2

The luajit and lua51 internal API didn't take a `mode` variable, meaning
the function signature was different between these two versions and lua
5.2+. Add an unused `Mode` to the loadFile51 signature to allow building
with luajit/lua51

The checkVersion function calls luaL_checkversion, which was only
introduced in lua 5.2. Add an empty call when using a version less than
5.2
@natecraddock
Copy link
Owner

Hey thank you for this contribution! So I'm actually unsure how I want to address this. From the perspective of making the API consistent across all Lua versions this is a good fix. But I'm not sure if that is the direction I want to take ziglua.

For example, you fixed loadFile and checkVersion, but there are many other functions with inconsistencies between the Lua versions.

Currently the approach to handle this is to use ziglua.lang in your code to handle any cases where a function differs or isn't available. Would this be a reasonable approach for you? I'm happy to discuss this further to find other solutions

@rockorager
Copy link
Author

rockorager commented Apr 21, 2024 via email

@rockorager
Copy link
Author

rockorager commented Apr 21, 2024 via email

@rockorager
Copy link
Author

I guess email replies don't work well with code formatting.

I think the second fix keeps the ziglua 5.1 api the same as lua5.1 (one param for loadFile) and also allows lua5.1 users to call doFile since it only passes one param at the callsite - I believe this addresses your concern but let me know if I am missing something!

@natecraddock
Copy link
Owner

Hey there! So sorry for leaving this hanging so long. I've been super swamped the last month. I'll take a closer look later today / over the next few days and get back to you

natecraddock added a commit that referenced this pull request Jul 19, 2024
doFile didn't properly handle different versions

See #79
@natecraddock
Copy link
Owner

I see it wasn't quite clear the trace I was calling to get to why I fixed
loadFile. I am calling dofile("foo.lua") in luajit, which in turn calls
loadFile with two parameters. Perhaps the fix for this should actually be a
switch in the doFile function for how it calls loadFile:

/// Loads and runs the given file
/// See https://www.lua.org/manual/5.4/manual.html#luaL_dofile
pub fn doFile(lua: *Lua, file_name: [:0]const u8) !void {
    // translate-c failure
    switch (lang) {
        .luajit, .lua51 => try lua.loadFile(file_name),
        else => try lua.loadFile(file_name, .binary_text),
    }
    try lua.protectedCall(0, mult_return, 0);
}

It took me reading this PR several times, and the source code to comlink to finally figure it out what you explained so simply... sometimes reading is hard 😂

I just merged a fix with this above suggested approach. Thanks!
The reason this slipped by is I never added test coverage for loadFile and doFile 🙈 That is also part of the commit.

Thanks for raising this issue, and sorry for the delay!

Also I'm leaving checkVersion untouched, but feel free to open an issue or PR if you think there is something to be done there.

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.

None yet

2 participants