Skip to content
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

[Q] Catch lua error #88

Closed
trsh opened this issue Sep 9, 2018 · 10 comments
Closed

[Q] Catch lua error #88

trsh opened this issue Sep 9, 2018 · 10 comments

Comments

@trsh
Copy link

trsh commented Sep 9, 2018

Can I catch and Faulty lua code, and get some stack trace without panicking the main Rust code?

@trsh
Copy link
Author

trsh commented Sep 9, 2018

Additionally how do I set a glob val that is == nil / empty?

@trsh
Copy link
Author

trsh commented Sep 10, 2018

Never mind

@trsh trsh closed this as completed Sep 10, 2018
@naturallymitchell
Copy link

@trsh you're gonna post a good question, figure it out, then leave us hanging?

what'd you find??

@trsh
Copy link
Author

trsh commented Oct 15, 2018

@mitchtbaum for the 1st question:

      let eval_res = lua.eval::<String>(code, None);
      match eval_res {
        Ok(val) => {
          
        }
        Err(e) => {
          
        }
      }

e will contain Lua errors.

For the nil question, my answer is just not to set that Global. And it will be nil, as all undefined variables in Lua.

@naturallymitchell
Copy link

naturallymitchell commented Oct 15, 2018

@trsh these say to use xpcall. is that another approach?

what about try-catch error handling exception pattern? are these ever used together?

I posted an issue in the framework I'm working on. if you're also interested in actix-web and lua, then I'd love your input.

@trsh
Copy link
Author

trsh commented Oct 15, 2018

@mitchtbaum sorry, I can tell nothing more. My approach is working for my project, so i dont investigate further. And I use actix-web.

@trsh
Copy link
Author

trsh commented Oct 15, 2018

@mitchtbaum one thing that I wan't, and could not figure out, is how to get print (printed stuff in lua), to Rust back. If you know that, let me know. For now I throw exceptions to debug stuff.

@naturallymitchell
Copy link

I'm not sure I understand. what is the goal? to pipe stdout back to Rust? I thought you already showed you can get the error object. Does throwing an exception give different debug output?

@naturallymitchell
Copy link

I think if it happens anywhere in my code base, it'd be here

https://github.com/foundpatterns/torchbear/blob/aadee3f603c9a1d1dd2ded5d3f579300a704561a/src/lua_bindings/log.rs#L6-L15

that receives strings from Lua to use in Rust code, I think evidenced by its use of push and push_str()

we're not using it anymore, since we switched to using log.lua

@trsh
Copy link
Author

trsh commented Oct 15, 2018

Throwing an exception returns Error to Rust, that includes the error lines. Ok result return whatever you return with "return xx". So Print invisible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants