Comments (4)
Could this be solved by borrowing the value (which requires knowing its type, which shouldn't be a big hurdle for us) and then getting a pointer to the inner value?
e.g:
let ref = user_data.borrow::<Tag>()?;
println!("Pointer is {:p}", &*ref as *const Tag);
from rlua.
Uhm... now I wonder what the problem was that made me conclude that the above does not work. However, I have no idea what that was....O.o
(Perhaps I got confused by the get_object()
function in way-cooler since that clones the object...)
Sorry for the noise!
from rlua.
I'm glad you got it figured out! I didn't know about __name
before, and apparently it's used by some error reporting functions as well? I might look into allowing that to be set on userdata metatables, but like everything else on userdata metatables it would probably be the same for all instances of a UserData.
from rlua.
Could this be solved by borrowing the value (which requires knowing its type, which shouldn't be a big hurdle for us) and then getting a pointer to the inner value?
The short version: Yes, but I forgot to do a dereference (*
) when testing. You apparently did not forget this. :-)
Okay, I finally had the time to actually try this and... it does not work.
extern crate rlua;
use rlua::{Lua, AnyUserData, UserData, Result};
struct MyData();
impl UserData for MyData {}
fn run() -> Result<()> {
let lua = Lua::new();
lua.globals().set("object", MyData())?;
let value = lua.globals().get::<_, AnyUserData>("object")?;
println!("{:?}", &value.borrow::<MyData>()? as *const _);
println!("{:?}", &value.borrow::<MyData>()? as *const _);
println!("{:?}", &value.borrow::<MyData>()? as *const _);
Ok(())
}
fn main() {
run().unwrap()
}
Output (example):
0x7ffe4c9944d0
0x7ffe4c9946a0
0x7ffe4c994870
So apparently I already tried this, but forgot about the details when I closed this issue five days ago.
The return type of borrow()
is std::cell::Ref
, so what the code above actually prints is the address of this instance of Ref
.
Instead, I need to do the following (note the extra *
) so that Ref
is dereferenced and I actually take the address of the contained object:
println!("{:?}", &value.borrow::<MyData>()? as *const _);
...and with this modification, things actually start working.
from rlua.
Related Issues (20)
- Possible bug with __newindex not called on numeric indexing HOT 4
- 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.