lua on raspberry pi... require() returning nil

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

lua on raspberry pi... require() returning nil

John Langley
I'm using lua 5.2 (local built) on raspbian and it seems that every C module I try and use returns nil from the require. 

If I have LUA_CPATH setup wrong, I get complaints about not finding the library. But it seems that even though lua (the REPL) can find the libraries, they don't get initialized properly when loaded with require. 

Note: I added an -fPIC to my local build of lua, but that didn't seem to help this matter. 

Thanks in advance, I'm very excited about using Lua and it's REPL to speed development on the RPi, but this is a show stopper for me right now. 

-- J
Reply | Threaded
Open this post in threaded view
|

Re: lua on raspberry pi... require() returning nil

Ignacio Burgueño-2
Hi John. Since you mention using the REPL, could it be that you're assigning the return of require to a local?

> local m = require("m")

If that's the case, bear in mind that each line you enter in the REPL is run in a new scope.
See "Why are local variables difficult in the interactive interpreter" here: http://lua-users.org/wiki/ScopeTutorial
Reply | Threaded
Open this post in threaded view
|

Re: lua on raspberry pi... require() returning nil

John Langley
Yes! That was exactly what I was doing. Thank you SO MUCH. I'm definitely a newbie and should have qualified my question that way. 

Thank you again! 

- J 

On Fri, Sep 18, 2015 at 12:13 PM Ignacio Burgueño <[hidden email]> wrote:
Hi John. Since you mention using the REPL, could it be that you're assigning the return of require to a local?

> local m = require("m")

If that's the case, bear in mind that each line you enter in the REPL is run in a new scope.
See "Why are local variables difficult in the interactive interpreter" here: http://lua-users.org/wiki/ScopeTutorial