"strange" string comparison fallure

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

"strange" string comparison fallure

Laurent FAILLIE
Hello,

Can someone explains to me why the following code is failling ?

----
function Command( topic, val )
print('cmd', topic, '"'..val..'"')
print(type(val))
    if val == "Grab" then
print 'grab'
        srf:Dump('/tmp', 'DashBoard')
    else
print("different")
    end
end
-----

The output is the follwing :

----
cmd    HomeDashBoard/Tablette/Command    "Grab"
string
different
----

As you can see the received string is Grab and is supposed to match the if statement ... but is not.

It's probably a stupid mistake ... but where ?

Thanks

Laurent
Reply | Threaded
Open this post in threaded view
|

Re: "strange" string comparison fallure

Enrico Colombini
On 25-Oct-15 11:53, Laurent FAILLIE wrote:
>      if val == "Grab" then
 > [...]
> As you can see the received string is Grab and is supposed to match the if statement ... but is not.
> It's probably a stupid mistake ... but where ?

Invisible characters in the above string literal?

--
   Enrico

Reply | Threaded
Open this post in threaded view
|

Re: "strange" string comparison fallure

Jeff Pohlmeyer
In reply to this post by Laurent FAILLIE
On Sun, Oct 25, 2015 at 5:53 AM, Laurent FAILLIE <[hidden email]> wrote:

>     else
> print("different")

print("different: ", #val, #"Grab")
for i=1,#val do print(val:byte(i),'=',val:sub(i,i)) end


- Jeff

Reply | Threaded
Open this post in threaded view
|

Re: "strange" string comparison fallure

Laurent FAILLIE
In reply to this post by Laurent FAILLIE
Hi,

Well, I found out where the problem is : this function is launched from another thread, for which the context as been created using lua_newState() followed obviously by luaL_openlibs().
But it seems in this new context strings functions don't exists :
        Selenite/HDB.sel:316: attempt to call global 'strlen' (a nil value)
so I guess it's the same for string comparison : I think I missed something that made strings unknown to Lua.

Where did I made a mistake ?

Thanks

Laurent




Le Dimanche 25 octobre 2015 11h53, Laurent FAILLIE <[hidden email]> a écrit :


Hello,

Can someone explains to me why the following code is failling ?

----
function Command( topic, val )
print('cmd', topic, '"'..val..'"')
print(type(val))
    if val == "Grab" then
print 'grab'
        srf:Dump('/tmp', 'DashBoard')
    else
print("different")
    end
end
-----

The output is the follwing :

----
cmd    HomeDashBoard/Tablette/Command    "Grab"
string
different
----

As you can see the received string is Grab and is supposed to match the if statement ... but is not.

It's probably a stupid mistake ... but where ?

Thanks

Laurent