-
-
Notifications
You must be signed in to change notification settings - Fork 483
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
How to parse usertype in C++ side from sol::table? #308
Comments
Other similar problems for me also include class, struct parsing in sol::table. |
What does "it failed at the data parsing ( I need more information to help you, as that looks like valid code that should work just fine. |
Thanks for letting me know. I still have a questions or two to figure this out. Did you provide a custom binding for "cd", or are you just using the plain binding? The error indicates that, somehow, the value for second is essentially a table: do you know if your The ONLY thing I can think of as going wrong here is that the table |
Yeah, you don't have to create bindings that specifically create Lua objects. sol2 handles any C++ type in the world, and serializes it as an "opaque pointer" kind of thing called a userdata (with member functions and variables, if you define them with If you need to customize how Good luck! |
ONE FINAL WORD OF WARNING: The iterators you use to walk through a It is NOT something you should rely on. If you want to figure out the length of a table, call the length operation ( |
Thanks for your suggestions, I have relpaced iterators with numeric indexing. |
The 'projection' is my binding function, and its return type is 'cd' (complex number). It seems I can successfully get the array table as follows:
local fid = {}
for i = 1, 1024 do
fid[i] = projection(i)
end
print(#fid)
Now I'd like to deal with the 'fid' table with C++.
cx_vec fft_1d(const sol::table& t) {
for (auto& kv : t) {
sol::object val = kv.second;
cout << val.as<cd>()<<"\n";
}
...
}
lua side:
local spec = fft_1d(fid)
But It failed at the data parsing (
val.as<cd>()
). Thanks for your help.The text was updated successfully, but these errors were encountered: