lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Mark Meijer wrote:
You could always combine the pointer equality and strcmp() (and/or other methods of equality testing), e.g:

char* myFoo = "foo";
char* prop = lua_tostring(L, -1);
if((prop == myFoo) || (strcmp(prop, myFoo) == 0))
[...]

Obviously if the pointers are equal then you are sure the strings are equal, so there's no harm in using this to your advantage (without relying solely on this) if chances are good that you can prevent the strcmp that way (or any other performance hits that other approaches impose).

But this is guaranteed to fail, isn't it? A Lua originated string is never going to have the same pointer as a C-generated string, right?

--
chris marrin                ,""$,
chris@marrin.com          b`    $                             ,,.
                        mP     b'                            , 1$'
        ,.`           ,b`    ,`                              :$$'
     ,|`             mP    ,`                                       ,mm
   ,b"              b"   ,`            ,mm      m$$    ,m         ,`P$$
  m$`             ,b`  .` ,mm        ,'|$P   ,|"1$`  ,b$P       ,`  :$1
 b$`             ,$: :,`` |$$      ,`   $$` ,|` ,$$,,`"$$     .`    :$|
b$|            _m$`,:`    :$1   ,`     ,$Pm|`    `    :$$,..;"'     |$:
P$b,      _;b$$b$1"       |$$ ,`      ,$$"             ``'          $$
 ```"```'"    `"`         `""`        ""`                          ,P`
"As a general rule,don't solve puzzles that open portals to Hell"'