lua-users home
lua-l archive

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


Hi Steve,
 
Many thanks for your reply. It worked by the approach that I put lpeg.so in the same directory with Lua, then start lua with lpeg load:
 
bin: lua -llpeg
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
>
 
After that, I tested example from LPeg reference book, and the result showed lpeg load work well.
 
bin: lua -llpeg
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> -- matches a numeral and captures its value
> number = lpeg.R"09"^1 / tonumber

> -- matches a list of numbers, captures their values
> list = number * ("," * number)^0

> -- auxiliary function to add two numbers
> function add (acc, newvalue) return acc + newvalue end

> -- folds the list of numbers adding them
> sum = lpeg.Cf(list, add)

> -- example of use
> print(sum:match("10,30,43"))   --> 83
83
 
But, when I tried to test test.lua scripts coming from lpeg-0.9, I got trouble below:
 
> local m = require"lpeg"
> any = m.P(1)
stdin:1: attempt to index global 'm' (a nil value)
stack traceback:
        stdin:1: in main chunk
        [C]: ?
 
It looks like the statement require"lpeg" does not return correct module address. If trying statement local m = lpeg, the result is the same
 
> local m = lpeg
> any = m.P(1)
stdin:1: attempt to index global 'm' (a nil value)
stack traceback:
        stdin:1: in main chunk
        [C]: ?
>
 
The all above were the first issue.
 
Another issue was regarding LUA_CPATH.
Due to account privilege limitation on Solaris server machine, I was not able to install lua under /usr/local/bin or /usr/local/lib. So the form  /home/my_account/bin, /home/my_account/include, /home/my_account/lib, etc was chosen, then added /home/my_account/bin to PATH so that I was able to run lua anywhere. I hope "/home/my_account/lib/lua/5.1/?.so" could be appended to LUA_CPATH, any extend .so file were moved into "/home/my_account/lib/lua/5.1/?.so", obviously I could load lpeg by require"lpeg" conveniently. I ever tried adding "/home/my_account/lib/lua/5.1/?.so" to LUA_CPATH, however, which did not work like I imaged. Could you give me a solution of this issue?

thanks a lot.

在2010-03-04 19:49:56,"steve donovan" <steve.j.donovan@gmail.com> 写道:
>2010/3/4 leeya <leeyacn@126.com>:
>> But I did not know how to register lpeg.so to Lua so that I was able to use
>> LPeg by interactive ways.
>
>require ("lpeg") is what you need to do.  But first you must move
>lpeg.so onto the Lua extension path.
>
>On Linux, usually it is like so:
>
>$ lua -e "print(package.cpath)"
>./?.so;/usr/local/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so
>
>Which means that you should move lpeg.so to /usr/local/lib/lua/5.1
>
>However, if you are just testing an extension, note the ./?.so: it
>means that if you run Lua in the same directory as lfs.so, then
>require should work directly.
>
>steve d.