Undifined String Parameter NULL or ""

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Undifined String Parameter NULL or ""

mos-4

Hi!
I have a function c++ side regist by luabind like:

void Hi(const char* szHi)
{
        cout << szHi << endl;
}

and at lua side, when call Hi(temp); // temp not define.
will call Hi(NULL) and then the program will crash.

I wonder if I can modify some code of luabind when call Hi(temp); // temp
not define.
will call Hi(""), and then the program just donothing.

Best Regards
mos



-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Undifined String Parameter NULL or ""

Josh Green-3
A few things....

Hi(NULL)
will crash the program, because you are telling the program to output a NULL
string.

cout << NULL << endl; //This will crash it as well

Hi("") does of course work, it doesn't output anything much because the
sting you put in was blank, try:

Hi("Hello World")

finally:

Hi(temp)

will not work because you havn't defined temp
try:

temp = "Hello World from Temp!"
Hi(temp)

--------------ORIGINAL MESSAGE------------
Hi!
I have a function c++ side regist by luabind like:

void Hi(const char* szHi)
{
        cout << szHi << endl;
}

and at lua side, when call Hi(temp); // temp not define.
will call Hi(NULL) and then the program will crash.

I wonder if I can modify some code of luabind when call Hi(temp); // temp
not define.
will call Hi(""), and then the program just donothing.

Best Regards
mos



-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Undifined String Parameter NULL or ""

Marko Ludolph-2
You must change your C++ program, not luabind. E.g. like this:

void Hi(const char* szHi)
{
       if(szHi) // check, if the string is not a null pointer
       {
         cout << szHi << endl;
       }
}

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Undifined String Parameter NULL or ""

Enno Rehling
In reply to this post by Josh Green-3
I think what he wants is that when he's passing a null-pointer to a
function that receives const char*, luabind should magically guess that
his function will crash on null-pointers as input and therefor should
automatically pass "" instead. Of course, luabind will do no such thing,
and it shouldn't.

You have to make your C++ function deal with the null-pointers instead.

Enno.


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Undifined String Parameter NULL or ""

Evan Wies
Theoretically, I think one could write a null_pointer_policy that checks for NULL on a pointer
before considering the conversion valid.

module(L)
{
        def( "Hi", &Hi, null_pointer_policy(_1) )
}

Writing policies isn't documented though, but you could experiment by looking at the policies in the
luabind include directory.

-Evan


Enno Rehling wrote:

> I think what he wants is that when he's passing a null-pointer to a
> function that receives const char*, luabind should magically guess that
> his function will crash on null-pointers as input and therefor should
> automatically pass "" instead. Of course, luabind will do no such thing,
> and it shouldn't.
>
> You have to make your C++ function deal with the null-pointers instead.
>
> Enno.
>
>
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user