Comments (2)
Changed the documentation in the guided tour, hopefully this is clearer.
Also for future reference in case somebody looks at this issue, what I wrote about UserData
types requiring 'static
is no longer true, Scope
can now lift both Send
and 'static
requirements.
from rlua.
Yeah the GC is running in a call to Lua::scope
for sure, the text "lifting both of these restrictions" is meant to reference the fact that userdata must be Send
and 'static
. I'll figure out a better way of wording it, or simply drop the reference to the GC at all.
The reason I mention the GC is because that is the reason WHY userdata must be 'static
: since we don't know when Lua will get around to garbage collecting our userdata, we can't make any assumptions about the lifetimes of any references in the userdata. Lua::scope
forces the userdatas to be destructed at the exit of the scope.
Edit: also, similarly, this is why we can let userdata be Send. In the context of a Lua::scope
call, Lua has a live reference, so it would be impossible to give that Lua to another thread while inside a scope call. Since all the userdata created in a scope will be forcibly dropped at the end of the scope call, it's okay if they aren't Send since you could never store !Send
userdata inside Lua long term.
Unfortunately, you can't take away the 'static
restriction on UserData
types because they are accessible based on TypeId, and that is sort of fundamentally unsafe with non-'static types (you can manufacture any lifetime you want inside a UserData
method).
Note: I'm using lowercase 'userdata' here to refer to the Lua concept of userdata, which in this case includes both callbacks with state and also types that implement the UserData
trait.
Edit 2: I guess mentioning the GC at all is really unnecessary, as there are really countless ways of Lua extending the lifetime of something, I'll just reword it to not mention the GC at all.
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.