lua-users home
lua-l archive

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

New to Lua.  Still trying to understand why 'require' does not work very well.
I cannot get Lua to find a lib unless I place the exe in the same folder next to the lib.  The 'require' statement does not use paths it seems, and linking often does not work since some libs have no sonames and are not named according to standard practices. Some libs require symlinks to other libs etc.

For pure lua the error paths I get are:
$ lua hello.lua
lua: hello.lua:4: module 'random' not found:
    no field package.preload['random']
    no file './random.lua'
    no file '/usr/share/lua/5.1/random.lua'
    no file '/usr/share/lua/5.1/random/init.lua'
    no file '/usr/lib/lua/5.1/random.lua'
    no file '/usr/lib/lua/5.1/random/init.lua'
    no file './'
    no file '/usr/lib/lua/5.1/'
    no file '/usr/lib/lua/5.1/'
stack traceback:
    [C]: in function 'require'
    hello.lua:4: in main chunk
    [C]: ?

O.K. so I copied the to /usr/lib/lua/5.1/ and this temp fix works; but the external libs I want to require are really more extensive than just 

What is a good solution to this problem?  How do you go about requiring external libs which have dependencies to other libs etc.?


print("*** HELLO! from Lua***")
x= 2
y = 3
z = x + y
print("sum of 2 + 3 is: ", z)

-- Lua Hello World (test.lua)
function myFunction ()
   io.write ("hello function World")
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <cstdlib>

extern "C" {
    #include "lua.h"
    #include "lualib.h"
    #include "lauxlib.h"
lua_State* L;

int main (int argc, char *argv[])
int status;
    L = luaL_newstate();
    status = luaL_loadfile(L, "hello.lua");
    if (status) {
        /* If something went wrong, error message is at the top of */
        /* the stack */
        fprintf(stderr, "Couldn't load file: %s\n", lua_tostring(L, -1));

    return 0;

Hotmail: Trusted email with powerful SPAM protection. Sign up now.