-
-
Notifications
You must be signed in to change notification settings - Fork 514
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
Registering String Types #140
Comments
You'd need to customize several points to make this work for you. It'd look something like the following: #include <sol.hpp> // or whatever you currently are using to include sol
namespace sol { namespace stack {
template <>
struct pusher< ::wxString > { // or whatever the full qualified name is
static int push ( lua_State* L, const ::wxString& str ) {
return stack::push(L, str.c_str()); // or whatever would need to be done
// documentation for wxString suggests that data can be stored UTF8/16/32, depending on compiler flags
// You will need to find out how you want to handle that (we don't handle wchar_t or char16_t or char32_t strings since that means we'd need to also build into Sol unicode conversion routines
}
};
template <>
struct getter< ::wxString > {
static ::wxString get ( lua_State* L, int index ) {
const char* luastr = stack::get<const char*>(L, index);
// Lua generally works with ASCII or UTF8 strings, so you'd need to convert internally to what ::wxString offers
}
};
} // stack
template <>
struct lua_type_of< ::wxString > : std::integral_constant<type, type::string> {};
} //sol
That does look like a lot of work, though... I should consider making things more extensible for other basic types (like the many string types). Either way, that's how you'd get wxString to get pushed into Lua like a string and read from Lua like a string. You're going to need to full in the blanks, as I don't know what you're compiling for wxWidgets and if you're going to need to do conversions. My hope is that you're doing UTF8, which means you'll be able to just |
Woww! That looks great! Thanks for fast reply! I will try it right now. 👍 :D |
After the latest release, applying this method causes a lot of compiler problems. What should I change? |
Oops, right. I forgot to mention this. I formalized the getter/pusher/checker architecture and documented it, so your changes would be minimal (you just need to handle the It would probably look like this: namespace sol { namespace stack {
template <>
struct pusher< ::wxString > {
static int push ( lua_State* L, const ::wxString& str ) {
// same as before
}
};
template <>
struct getter< ::wxString > {
static ::wxString get ( lua_State* L, int index, record& tracking ) {
tracking.use(1); // THIS IS THE ONLY BIT THAT CHANGES
const char* luastr = stack::get<const char*>(L, index);
// same as before
}
};
} // stack
template <>
struct lua_type_of< ::wxString > : std::integral_constant<type, type::string> {}; |
This is not a bug report, just a question. Your library handles
std::string
very well. But I have another type of strings:wxString
from wxWidgets. Can Sol2 and new string types work well together? How could I register them to asol::state
?Thank you.
The text was updated successfully, but these errors were encountered: