-
Notifications
You must be signed in to change notification settings - Fork 45
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
How safe is State::error? #37
Comments
From the reference:
All bets are off if you raise a Lua error outside of a pcall. I think to properly handle this, |
Hi, When thinking about what I could do about this, I thought it would be nice if the Rust function could be written like: fn myFunction(state: &mut lua::State) -> Result<c_int, String> {
...stuff with try!() etc.
} where an So it would go something like:
With those layers in place, I could then write reasonably natural Rust functions and have errors translated automatically. I think I've got all I need to implement this on top of rust-lua53 without any changes your end, though it would be convenient (and I guess a little faster) if the library supported calling I'd be interested in any comments/suggestions/obvious problems with my mad scheme above, but I'm happy to close this issue now; but I'll leave that to you in case you want to implement anything. |
I've been working on some things quite similar to this here (see fn my_function(environment: Environment) -> Result<i32, Box<Error>> {
// ...
Ok(1)
} @jugglerchris Perhaps you'd be interested in collaborating on a higher-level Rust-Lua library? I've got some neat ideas that don't really fit into this project (from my understanding, this is meant to be a 1:1 Rust binding to Lua). |
@CoderStephen I was planning on (eventually) splitting out what I have into a separate crate; I'd be happy to work together. I've implemented the scheme in my above comment and a way to safely share Rust types in what I think is a (dynamically) type-safe way with Lua. I'll try to prioritise getting that up somewhere, hopefully sometime this week. |
I've split out my in-development (badly documented, inconsistently named and so on) interface into a github repo: https://github.com/jugglerchris/rlua in case it's of interest. It's all a bit messy and rough at the moment, but I'm happy for that to be a starting point for a more generally useful and Rustic (is that the word?) interface on top of this one. |
Hi,
I'm trying to work out how safe calling the error method is, for reporting problems back to Lua code. It causes longjmp to unwind past a Rust function, which sounds undefined, but can it be safe if I'm careful?
I'd be interested in both "in practice ok" and "yes it's correct" type answers.
Thanks,
Chris
The text was updated successfully, but these errors were encountered: