lua-users home
lua-l archive

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


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi guys,

I'm kinda new to lua and have been trying it for some time now. Well, I
must say I'm really happy with the results! However, I found some
*problems*, and so I'd like to ask some questions... answers are
appreciated!

- -- First question:

> f = function() return 1,99 end
> x = 2 or f()
> print(x)
2
> x = nil or f()
> print(x)
1
> _,x = _,2 or f()
> print(x)
2
> _,x = _,nil or f()
> print(x)              -- x = 1 !!!
1

Shouldn't be 99?

- -- Second question:

> s = 'just a test'
> print(string.gfind(s, "([%w%p]+)%s+([%w%p]+)$")())    -- ok
a   test
> print(string.gfind(s, "([%w%p]+)%s+([%w%p]+)")())     -- ok
just    a
> print(string.gfind(s, "^([%w%p]+)%s+([%w%p]+)")())    -- returns nil !!!

> s = '^just a test'
> print(string.gfind(s, "^([%w%p]+)%s+([%w%p]+)")())    -- now it works !!!
just    a

Why the caret is being taken *literally*? Shouldn't it be a special char
indicating a regex start anchor?

So far, I have managed to find some workarounds for these situations...
but a better solution would be much more desirable! Thanks in advance.
:)

Regards,
Luis.

- -- 
Mathematicians practice absolute freedom.
                -- Henry Adams

- -- 
Luis Carvalho
Applied Math PhD Student
Brown University
carvalho at dam dot brown dot edu

PGP Key: E820854A <carvalho@dam.brown.edu>
Available at: http://www.dam.brown.edu/people/carvalho/pgp-key
Fingerprint: 1339 9E5D DB0B 01B9 624D  AFF8 D738 BFA6 E820 854A

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE/OBMO1zi/pugghUoRAncFAJ9DMhgUOga2BrVuni3tTV7N7nw+NgCcD4bA
DCdemveNZ3lkVuMHOa4Tr1s=
=Pxcj
-----END PGP SIGNATURE-----