Comments (4)
Thanks for letting us know, and hope you find the issue!
from rlua.
And i think what makes me think this is a bug is that if I change the signature of the metamethod to force idx
to be a String
instead of a Value
calling comp.vec[0] = 5.4
results in a runtime error.
from rlua.
Hi,
I agree this doesn't sound right.
The only Lua behaviour that comes to mind is that if you have an ordinary table, then the __newindex
or __index
metamethods aren't called if the table already contains that key - but if it's a userdata that shouldn't be an issue.
Are you able to reproduce this in an ideally smaller rlua-only example (or at least something I can run and try out)?
from rlua.
Apologies for the delay, left for holiday very soon after posting this issue,
I've just gotten back and attempted to reproduce with a minimal example. I was unable to reproduce so this makes me think that this may very well be UB from my side (playing with bevy and pointers), I will close this for now but if i fix things on my side and still bump into this I will re-open and link to the full example.
Sorry!
For context this is what I tried and it works:
use rlua::{Value,UserData,MetaMethod,Function,prelude::*};
#[derive(Debug)]
pub struct MyUserData {
v : [u32;3]
}
impl UserData for MyUserData {
fn add_methods<'lua, T: LuaUserDataMethods<'lua, Self>>(methods: &mut T) {
methods.add_meta_method(MetaMethod::ToString, |_,s,()| {
Ok(format!("{:?}",s))
});
methods.add_meta_method_mut(MetaMethod::NewIndex, |_,s,(idx,val) : (Value,u32)|{
let idx = match idx {
Value::Integer(i) => i as usize,
Value::String(s) => match s.to_str().unwrap() {
"x" => 0,
"y" => 1,
"z" => 2,
_ => panic!()
},
_ => panic!(),
};
Ok(s.v[idx] = val)
})
}
}
fn main() {
let lua = Lua::new();
lua.context(|lua_ctx| {
lua_ctx
.load("
function on_update(my_user_data)
print(my_user_data)
my_user_data[0] = 69
my_user_data.y = 42
print(my_user_data)
end
")
.exec()
}).unwrap();
lua.context(|lua_ctx| {
let g = lua_ctx.globals();
let f : Function = g.get("on_update").unwrap();
f.call::<MyUserData,()>(MyUserData{
v: [0,1,2],
}).unwrap();
})
}
from rlua.
Related Issues (20)
- Question: How to exec multiple things at once? HOT 4
- Segfault on clone of #[repr(C)] userdata subfield HOT 9
- ios build error HOT 7
- examples for error handling HOT 2
- Example for eval return a struct? HOT 1
- Cannot load DLLs in v0.19 HOT 6
- Missing mutable borrows for Table<'lua> HOT 2
- Context.create_sequence_from should support references HOT 1
- Undefined symbol lua_checkstack HOT 8
- Crash on empty source HOT 2
- custom runtime path HOT 3
- creating a `require`-able module HOT 8
- [Request] UserData::from_lua HOT 1
- Suggestion: proc_macro for LuaUserDataMethods::add_method HOT 3
- No documentation on how to use LuaRocks with rlua HOT 3
- Rlua + Luarocks Modules -> Fail to load HOT 3
- Memory leak when using system-luajit HOT 2
- Merge with mlua HOT 32
- [Typo] Example says laoded(instead of loaded) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rlua.