-
-
Notifications
You must be signed in to change notification settings - Fork 166
[luajit] mlua does not recognize LL
/ULL
numbers as integers
#580
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
Comments
LL
/ULL
numbers as integersLL
/ULL
numbers as integers
This is because objects like
LuaJIT through their C API (e.g. Even LuaJIT standard stdlib methods cannot work with this type, see:
So this is rather luajit issue. There is little that can be done here. |
I see, thanks for the information! Is there a way how the type of fields.add_field_method_set("foo", |_, this, value: u64| {
this.foo = value;
Ok(())
}) so that it accepts the |
So this is what I implemented now: #[repr(transparent)]
#[derive(Debug, Clone, Copy)]
struct CInt<T>(T);
macro_rules! impl_cint {
($(($ty:ty, $suffix:literal)),*) => {
$(
impl FromLua for CInt<$ty> {
fn from_lua(value: mlua::Value, lua: &mlua::Lua) -> mlua::Result<Self> {
if let mlua::Value::Other(_)= value {
let str = value.to_string()?;
if let Some(int_str) = str.strip_suffix($suffix) {
if let Ok(int) = int_str.parse::<$ty>() {
return Ok(CInt(int));
}
}
}
Ok(CInt(<$ty>::from_lua(value, lua)?))
}
}
)*
};
}
impl_cint!((u64, "ULL"), (i64, "LL")); And the fields.add_field_method_set("foo", |_, this, value: CInt<u64>| {
this.foo = value.0;
Ok(())
}) Closing this issue, as there isn't really anything that can be done in |
In LuaJIT
LuaJIT/LuaJIT#1286
To force integers in luajit, you have to add the suffix
LL
orULL
. But when doing this and implementing something likethe following error is emitted:
when trying to set
MyStruct.foo = 0ULL
in a script run throughmLua
.The text was updated successfully, but these errors were encountered: