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

sol::no_constructor errors are incorrect/don't match the docs #346

Closed
squeek502 opened this issue Feb 20, 2017 · 3 comments
Closed

sol::no_constructor errors are incorrect/don't match the docs #346

squeek502 opened this issue Feb 20, 2017 · 3 comments
Assignees
Labels
Bug.Well Shit Here we go again...
Milestone

Comments

@squeek502
Copy link
Contributor

squeek502 commented Feb 20, 2017

From the docs:

{anything}, sol::no_constructor

  • {anything} should probably be "new", which will specifically block its creation and give a proper warning if someone calls new (otherwise it will just give a nil value error)

The errors that actually occur:

-------------------------------------------------------------------------------
no_constructor usage
  regular method 1
-------------------------------------------------------------------------------
..\no_constructor.cpp(11)
...............................................................................

..\no_constructor.cpp(16): FAILED:
  REQUIRE_NOTHROW( lua.script("a = thing.new()") )
due to unexpected exception with message:
  lua: error: caught (...) exception

-------------------------------------------------------------------------------
no_constructor usage
  regular method 2
-------------------------------------------------------------------------------
..\no_constructor.cpp(19)
...............................................................................

..\no_constructor.cpp(24): FAILED:
  REQUIRE_NOTHROW( lua.script("a = thing.new()") )
due to unexpected exception with message:
  lua: error: caught (...) exception

-------------------------------------------------------------------------------
no_constructor usage
  simple method 1
-------------------------------------------------------------------------------
..\no_constructor.cpp(27)
...............................................................................

..\no_constructor.cpp(32): FAILED:
  REQUIRE_NOTHROW( lua.script("a = thing.new()") )
due to unexpected exception with message:
  lua: error: [string "a = thing.new()"]:1: attempt to call field 'new' (a
  userdata value)

-------------------------------------------------------------------------------
no_constructor usage
  simple method 2
-------------------------------------------------------------------------------
..\no_constructor.cpp(35)
...............................................................................

..\no_constructor.cpp(40): FAILED:
  REQUIRE_NOTHROW( lua.script("a = thing.new()") )
due to unexpected exception with message:
  lua: error: [string "a = thing.new()"]:1: attempt to call field 'new' (a
  userdata value)

The test case (note: will fail even with proper error messages, this is just to see what the error messages look like; the test will need to look different to test that the errors are correct):

TEST_CASE("no_constructor usage")
{
	struct thing {};

	sol::state lua;
	lua.open_libraries(sol::lib::base);

	SECTION("regular method 1")
	{
		lua.new_usertype<thing>("thing",
			sol::meta_function::construct, sol::no_constructor
		);
		REQUIRE_NOTHROW(lua.script("a = thing.new()"));
	}

	SECTION("regular method 2")
	{
		lua.new_usertype<thing>("thing",
			"new", sol::no_constructor
		);
		REQUIRE_NOTHROW(lua.script("a = thing.new()"));
	}

	SECTION("simple method 1")
	{
		lua.new_simple_usertype<thing>("thing",
			sol::meta_function::construct, sol::no_constructor
		);
		REQUIRE_NOTHROW(lua.script("a = thing.new()"));
	}

	SECTION("simple method 2")
	{
		lua.new_simple_usertype<thing>("thing",
			"new", sol::no_constructor
		);
		REQUIRE_NOTHROW(lua.script("a = thing.new()"));
	}
}
@ThePhD
Copy link
Owner

ThePhD commented Feb 20, 2017

I get proper errors for the first 2, but not the second 2. I'll fix that and update the docs.

I don't know why you're getting a lua: error: caught (...) exception. It sounds like you might be using LuaJIT, and the trampoline might be gagging the real error.

@ThePhD ThePhD self-assigned this Feb 20, 2017
@ThePhD ThePhD added the Bug.Well Shit Here we go again... label Feb 20, 2017
@ThePhD ThePhD added this to the BugsDamnit milestone Feb 20, 2017
@ThePhD
Copy link
Owner

ThePhD commented Feb 20, 2017

Fixed: https://github.com/ThePhD/sol2/releases/tag/v2.15.9

@ThePhD ThePhD closed this as completed Feb 20, 2017
@squeek502
Copy link
Contributor Author

squeek502 commented Feb 20, 2017

Thanks for the fix, I'm still getting the ... exception for regular usertypes for some reason. I'm using standard Lua 5.1.5 compiled as C++ with SOL_USING_CXX_LUA and the MSVC14 compiler. If you'd like to investigate why that is happening any further, then let me know if there's any information you need from me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug.Well Shit Here we go again...
Projects
None yet
Development

No branches or pull requests

2 participants