lua-users home
lua-l archive

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

I once had this problem, too. Use either 


to open ALL libraries at once, or look at the source of this function to see
how they are called if you must open only specific libraries. For a test app
openlibs should suffice though.

See 7.3 - Changes in the API (first bullet point): 

-----Ursprüngliche Nachricht-----
[] Im Auftrag von Edward Mitchell
Gesendet: Sonntag, 24. September 2006 17:41
An: Lua list
Betreff: Unitialized Lua Stae using 5.1 causes abort

I am trying to get a test program to work using Lua 5.1.  The initialization
sequence in the main console program is:

void main(void)
    lua_State *pLuaState = lua_open();
and my program dies in luaopen_io(...).  I am using VS.NET 2003 to build the
library (LuaLib.lib) and run this test program.

Inside luaopen_io(..) is:

LUALIB_API int luaopen_io (lua_State *L) {
    /* create (private) environment (with fields IO_INPUT, IO_OUTPUT,
__close) */
    lua_createtable(L, 2, 1);
    lua_replace(L, LUA_ENVIRONINDEX);
The lua_replace() leads to o=index2adr(L, idx) with the idx value -1001.

The problem is caused here:

      Closure *func = curr_func(L);
      sethvalue(L, &L->env, func->c.env);

where the curr_func() returns 0xcdcdcdcd which is Microsoft speak for
uninitialised memory and the program dies at the line following.

The curr_func() is a macro defined by:

#define curr_func(L) (clvalue(L->ci->func))

The lua_State has a valid pointer for the ci->func.  The problem seems to
originate in the access to the value (via clvalue() macro) which is

How can I initialize the program properly?

Edward E.L. Mitchell
Phone: (508)771-0806
500 Ocean St., Unit 134,
Hyannis, MA 02601