lua-users home
lua-l archive

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


I am completely new to Lua so please bare with me as I learn. I am
tring to make a simple test application that just lets me embed lua
into a C++ application. I have been reading the "Programming in Lua"
book online and I just followed the example exactly as written. I am
using Lua v5.1.1, Windows XP-SP2, and MinGW to compile my application.
I am including the lua source right in my project and every time I run
my application I get this error:

   PANIC: unprotected error in call to Lua API (no calling environment)

I have tracked it down to the line:
   luaopen_io(L);
If I comment it out I can use the interpreter as I would expect.

Here is the source for main.cpp

int main( int argc, char* argv[] )
{
   char buff[256];
   int error;
   lua_State *L = lua_open();   /* opens Lua */
   luaopen_base(L);             /* opens the basic library */
   luaopen_table(L);            /* opens the table library */
   luaopen_io(L);               /* opens the I/O library */
   luaopen_string(L);           /* opens the string lib. */
   luaopen_math(L);             /* opens the math lib. */

   while (fgets(buff, sizeof(buff), stdin) != NULL)
   {
       error = luaL_loadbuffer(L, buff, strlen(buff), "line") ||
               lua_pcall(L, 0, 0, 0);
       if (error)
       {
           fprintf(stderr, "%s", lua_tostring(L, -1));
           lua_pop(L, 1);  /* pop error message from the stack */
       }
   }

   lua_close(L);
   return 0;
}

Any ideas?
--
Regards,
Ryan
RJP Computing