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

Sometimes it is not possible to catch sol::error #1469

Open
wzhengsen opened this issue Mar 28, 2023 · 2 comments
Open

Sometimes it is not possible to catch sol::error #1469

wzhengsen opened this issue Mar 28, 2023 · 2 comments

Comments

@wzhengsen
Copy link

My IDE: Microsoft Visual Studio Community 2022 v17.4.5

The code 1:

#define SOL_ALL_SAFETIES_ON 1
#define SOL_SAFE_FUNCTIONS 0
#include <sol/sol.hpp>
#include <iostream>

int main() {
    sol::state lua;
    try {
        sol::function f = lua[""];
        f();
    }
    catch (const sol::error& e) {
        std::cout << e.what() << std::endl;// Yes,I catched it.
    }
    return 0;
}

The code 2:

#define SOL_ALL_SAFETIES_ON 1
#define SOL_SAFE_FUNCTIONS 0
#include <sol/sol.hpp>
#include <iostream>

int main() {
    sol::state lua;
    try {
        sol::table t = lua[""];// An uncatchable error was raised here.
    }
    catch (const sol::error& e) {
        std::cout << e.what() << std::endl;
    }
    return 0;
}
@Rochet2
Copy link

Rochet2 commented Mar 28, 2023

I tried the codes in godbolt and the first code does not throw at all.
The second code throws. lua: error: stack index -1, expected table, received nil: value is not a table or a userdata that can behave like one (type check failed in constructor)
GCC 10.1, Lua 5.3.5, Sol 3.2.1

So sounds like both codes may work differently in different environments.
Or maybe just different sol or lua versions handle the cases differently,

  1. https://godbolt.org/z/6anYEq6h5
  2. https://godbolt.org/z/ad7frnrEY

@wzhengsen
Copy link
Author

@Rochet2
I have provided a screen recording to reproduce the bug:
screen

This is my code:

#define SOL_ALL_SAFETIES_ON 1
#define SOL_SAFE_FUNCTIONS 0
#include <sol/sol.hpp>
#include <iostream>

int main() {
    std::cout << SOL_VERSION << std::endl;
    std::cout << LUA_VERSION << std::endl;

    sol::state lua;
    try {
        sol::function f = lua[""];
        f();
    }
    catch (const sol::error& e) {
        std::cout << e.what() << std::endl;
    }

    try {
       sol::table t = lua[""];
    }
    catch (const sol::error& e) {
       std::cout << e.what() << std::endl;
    }

    return 0;
}

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