lua-users home
lua-l archive

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

linux f10.  I have Lua installed and it runs from the command line.

$ lua
Lua 5.1.4  Copyright (C) 1994-2008, PUC-Rio

I built a library, random, editing the makefile to reflect the location of my Lua installation per instructions in the readme of the library sources.

In general I cannot get Lua "require" to work, unless the .lua is specifically located in the same folder as the library, and the compiled .cpp is executed also from within the same directory as the library.

The random library is one example. Other libraries have the same result when using lua "require".

Since new to Lua I am wondering how to use "require" to including external libs?
require "random"


print("*** HELLO! ***")
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) {
        fprintf(stderr, "Couldn't load file: %s\n", lua_tostring(L, -1));
    return 0;

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