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

Throw an error from a Property with location information included #294

Open
rpatters1 opened this issue Aug 31, 2022 · 1 comment
Open

Comments

@rpatters1
Copy link
Contributor

rpatters1 commented Aug 31, 2022

This is a followup to #293, which I have closed because it does not accurately describe the issue. I would like to throw an error out of c++ and have it appear as a runtime error in Lua with file and line number information. If I throw the error from a function created with addFunction, it works. However, if I throw the error from the same c++ function registered withaddProperty, I do not get the file and line number info.

I am using Lua 5.2.4, which I compile and embed directly into my program, along with LuaBridge.

Here is a test case that compiles and illustrates the issue:

static void throw_error()
{
   throw std::runtime_error("runtime error");
}

static void standalone_error()
{
   throw_error();
}

class error_class
{
public:
   int class_error() const
   {
      ::throw_error();
      return 0;
   }
};

void lua_connect(lua_State *L)
{
   luabridge::getGlobalNamespace(L)
      .beginNamespace("test")
         .addFunction("standalone_error", standalone_error)
         .beginClass<error_class>("error_class")
            .addConstructor<void (*) (void)>()
            .addFunction("class_error", &error_class::class_error)
            .addProperty("property_error", &error_class::class_error)
         .endClass()
      .endNamespace();
}

Here are three different ways to encounter this runtime error in Lua. Obviously, the first one it hits aborts the script, so you have to comment out the ones you don't want to see.

test.standalone_error() --> reports file and line number along with the error
local errorclass = test.error_class()
local x = errorclass:class_error() --> reports file and line number along with the error
local y = errorclass.property_error --> reports the error but no file or line number information
@rpatters1 rpatters1 changed the title Thrown an error from a Property with location information included Throw an error from a Property with location information included Sep 2, 2022
@kunitoki
Copy link

This is fixed in luabridge3

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