lua-users home
lua-l archive

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


I am stuck.  I have a lua file called 'rules.lua' which declares the
following:

elementList = {}

function Node(anElement)
  -- Check validity of element data with respect to a node
  table.insert(elementList, anElement)
end

Then I have another lua file called 'nodes.lua' that looks something
like:

Node {
  id = 1
  name = "breaker"
}

Node {
  id = 2
  name = "pump"
}

In my C file I am doing the following:

void ReadNode()
{
        luaVM = lua_open();
        // Check to make sure open succeded
        if(luaVM == NULL)
        {
                cout << "Error Initializing LUA for nodes!" << endl;
                return;
        }
        // Initialize lua standard library functions
        lua_baselibopen(luaVM);
        lua_iolibopen(luaVM);
        lua_strlibopen(luaVM);

        lua_dofile(luaVM, "rules.lua");
        lua_dofile(luaVM,  "nodes.lua");
}

but when I call the function in C, I get the error:

rules.lua:12: attempt to index global `table' (a nil value)

What am I doing wrong?

TIA,

Steve

---------------------------------------------------------
Steven Woolsey                   EMAIL: woolsr@inel.gov
Senior Engineer/Scientist - Visualization Engineer
Idaho National Engineering and Environmental Laboratory
P.O. Box 1625, M.S. 3605, Idaho Falls, ID  83415-3605
---------------------------------------------------------