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

Tables, null, nil, AAH #383

Closed
ThePhD opened this issue Mar 30, 2017 · 1 comment
Closed

Tables, null, nil, AAH #383

ThePhD opened this issue Mar 30, 2017 · 1 comment
Assignees
Labels
Bike.Shed WHY IS THE TAG GOLD I WANTED TO PAINT IT RED-- Maybe.Bug...? Question.Arf?
Milestone

Comments

@ThePhD
Copy link
Owner

ThePhD commented Mar 30, 2017

Observe.

#define SOL_CHECK_ARGUMENTS

#include <sol.hpp>
#include <vector>
#include <map>
#include <cassert>
#include <iostream>

int main(int argc, char** argv) {
	struct test {
		int a = 20;
	};
	
	sol::state lua;

	test v;
	lua.create_named_table("tests",
		1, &v,
		2, nullptr,
		3, &v
	);

	lua["tests_2"] = std::vector<test*>( { &v, nullptr, &v } );

	lua.set_function("f", [](sol::as_table_t<std::vector<test*>> src) {
		std::vector<test*>& tests = src.source;
		std::cout << "f: ";
		for (const auto& t : tests) {
			std::cout << static_cast<void const*>(&t) << " ";
		}
		std::cout << std::endl;
	});

	lua.set_function("g", [](std::vector<test*>& tests) {
		std::cout << "g: ";
		for (const auto& t : tests) {
			std::cout << static_cast<void const*>(&t) << " ";
		}
		std::cout << std::endl;
	});
	lua.script(R"(
f(tests)
f(tests_2)
-- g(tests) -- this line would crash, is expected to
g(tests_2)
	)");
	return 0;
}

Results:

f: 000000846FCFF6E4
f: 000000846FCFF6E4
g: 000000846FCFF6E4 0000000000000000 000000846FCFF6E4

Meow

Only a problem with sol::as_table_t and other table-based operations that depend on what Lua calls a "sequence". Regular userdata-style containers are unaffected by what Lua considers to be a "break" or "hole" in a sequence (Goes from 1 to n, until it encounters a nil value, and has no other key-value pairs besides the upcounting integer ones). Should we do anything about it? One option is making a separate "nullptr" object in Lua. This seems like a non-issue when -- if a person uses "real" containers -- this can't happen and nulls can be embedded just fine...

@ThePhD ThePhD added Bike.Shed WHY IS THE TAG GOLD I WANTED TO PAINT IT RED-- Maybe.Bug...? Question.Arf? labels Mar 30, 2017
@ThePhD ThePhD added this to the Bikeshed milestone Mar 30, 2017
@ThePhD ThePhD self-assigned this Mar 30, 2017
@ThePhD
Copy link
Owner Author

ThePhD commented Apr 2, 2017

Buh. There's nothing we can really do about this that isn't just a patchjob. People will just have to be careful what they push into Lua and when they stick big fat nullptrs in the middle of pointer vectors?

@ThePhD ThePhD closed this as completed Apr 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bike.Shed WHY IS THE TAG GOLD I WANTED TO PAINT IT RED-- Maybe.Bug...? Question.Arf?
Projects
None yet
Development

No branches or pull requests

1 participant