Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


problem binding a c++ function with luabind


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 CDarwin   Members   -  Reputation: 105

Like
0Likes
Like

Posted 04 May 2013 - 11:30 AM

Hello,
 
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.
 

void STools::UCase(char *txt)

{

for (;;)

{

u_int32 t = *reinterpret_cast(txt);

...

txt++;

}

}


Here's the luabind code
 

luabind::module(myLuaState) [

    luabind::def("convert_upper", STools::UCase)

  ]; 


Compiler Error
 

 

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

 

Any help is appreciated!


Edited by CDarwin, 04 May 2013 - 11:30 AM.


Sponsor:

#2 Gambini   Members   -  Reputation: 384

Like
2Likes
Like

Posted 04 May 2013 - 04:33 PM

http://www.rasterbar.com/products/luabind/docs.html#out-value

 

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";
UCase(str);
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'


#3 CDarwin   Members   -  Reputation: 105

Like
0Likes
Like

Posted 05 May 2013 - 08:03 AM

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:

 

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

 

out_value(_2) causes the following:

 

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



#4 Gambini   Members   -  Reputation: 384

Like
0Likes
Like

Posted 05 May 2013 - 10:24 AM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS