-
Notifications
You must be signed in to change notification settings - Fork 48
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
Fix individual library open functions #147
base: master
Are you sure you want to change the base?
Conversation
@@ -27,6 +27,7 @@ pub const LUA_ERRERR: c_int = 6; | |||
pub struct lua_State; | |||
|
|||
pub type lua_CFunction = extern "C" fn(L: *mut lua_State) -> c_int; | |||
pub type lua_CFunction2 = unsafe extern "C" fn(*mut lua_State); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why I needed to create this type, I see other FFI declerations use the lua_CFunction
type, and the docs for requiref
don't seem any different to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not change the definition of luaL_requiref
to use lua_CFunction
instead?
EDIT: Ah nevermind, I see. I suppose you could also cast the function pointers instead.
I'd prefer if bindings remained identical to the C header.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is basically what I cobbled together from reading Rust's error messages and trying a bunch of random things. I really don't have the expertise to go much further.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should change open_helper
to accept a unsafe extern "C" fn(*mut lua_State)
instead of a ffi::lua_CFunction2
(which allows you to remove lua_CFunction2
from the bindings).
Then in open_helper
you should be able to do something like func as ffi::lua_CFunction
. If it doesn't work, use mem::transmute(func)
. It's the last resort solution, but at least it would compile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That still won't help the luaL_requiref
binding that needs the lua_CFunction2
though?
@@ -27,6 +27,7 @@ pub const LUA_ERRERR: c_int = 6; | |||
pub struct lua_State; | |||
|
|||
pub type lua_CFunction = extern "C" fn(L: *mut lua_State) -> c_int; | |||
pub type lua_CFunction2 = unsafe extern "C" fn(*mut lua_State); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should change open_helper
to accept a unsafe extern "C" fn(*mut lua_State)
instead of a ffi::lua_CFunction2
(which allows you to remove lua_CFunction2
from the bindings).
Then in open_helper
you should be able to do something like func as ffi::lua_CFunction
. If it doesn't work, use mem::transmute(func)
. It's the last resort solution, but at least it would compile.
See #146.
I think I got this mostly working, but since I have never programmed in C or used the Rust FFI before things could be totally broken.
The Lua 5.2 Docs say that you should use
requiref
to require individual libraries. So I basically implement this. My understanding of Lua internals is practically non-existent, so I hope this is right.Just one part I'm not sure how to do cleanly. See the line comment below.