Jump to content
  • Advertisement
Sign in to follow this  

problem binding a c++ function with luabind

This topic is 1990 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm pretty new to luabind. I'm having a little problem binding one of my string functions(convert to uppercase). Just couldn't figure it out.
[source]void STools::UCase(char *txt)
for (;;)
u_int32 t = *reinterpret_cast(txt);

Here's the luabind code
 [source]luabind::module(myLuaState) [
    luabind::def("convert_upper", STools::UCase)
  ]; [/source]

Compiler Error

 [source]error C2664: 'void (char *)' : cannot convert parameter 1 from 'const char *' to 'char *' [/source]


Any help is appreciated!

Edited by CDarwin

Share this post

Link to post
Share on other sites



That explains how your C++ functions can't take non-const ref/pointers if you want to bind them to Lua. So, the out_value function policy will add a return value in Lua code, rather than modifying the input.

Where your C++ code would look like

char* str = "hi";
std::cout << str; //prints 'HI'

Your Lua code would look like

local str = "hi"
local ucstr = UCase(str)
--// or you can have str = UCase(str)
print(ucstr) //prints 'HI'

Share this post

Link to post
Share on other sites

Thanks a lot Gambini,


I've tried your suggestion but I'm still getting compiler errors. Any other suggestions?


out_value(_1) causes the following error:


[SOURCE] error C2352: 'luabind::native_converter_base<T>::match' : illegal call of non-static member function[/SOURCE]


out_value(_2) causes the following:


[SOURCE]error C2664: 'void (char *)' : cannot convert parameter 1 from 'const char *' to 'char *'[/SOURCE]

Share this post

Link to post
Share on other sites

It looks like out_value doesn't work well with MSVC (here).


You'll have to either re-think the function or use Lua's "string.upper" function.


Another option is to make your own string class with UCase as a member function. That would bind perfectly fine to Lua, since UCase wouldn't need to take any parameters and only modify the object data.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!