Advertisement

Lua Crashing Program

Started by January 01, 2005 02:58 AM
1 comment, last by brcolow 20 years, 2 months ago
I am having a very strange problem, LUA is crashing my program. Now, that isn't the strange part. The strange part is that the code I am using in another program works without problems, but when added to my engine I get this: Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object. at fputs(SByte* , _iobuf* ) at ?A0x4c700a50.luaB_print(lua_State* L) at luaD_precall(lua_State* L, lua_TObject* func) at luaV_execute(lua_State* L) at luaD_call(lua_State* L, lua_TObject* func, Int32 nResults) at ?A0x4f8a2daa.f_call(lua_State* L, Void* ud) at luaD_rawrunprotected(lua_State* , IntPtr , Void* ) at luaD_pcall(lua_State* L, IntPtr func, Void* u, Int32 oldtop, Int32 ef) at lua_pcall(lua_State* L, Int32 nargs, Int32 nresults, Int32 errfunc) at ?A0x0a637578.aux_do(lua_State* L, Int32 status) at lua_dofile(lua_State* L, SByte* filename) I run everything through a gameManager, and inside that is the luaMgr that handles LUA. So, in main I call gameManager->luaMgr->LuaCreateState(); (which does more then just creating states, I moved everything into it for simplicity and for it to be EXACTLY like my test program. LuaCreateState() contains this:

void CLuaManager::LuaCreateState()
{

lua_State* luaVM = lua_open();
 
   if (NULL == luaVM)
   {
      printf("Error Initializing lua\n");
      return;
   }
    // initialize lua standard library functions

   lua_baselibopen(luaVM);
   lua_iolibopen(luaVM);
   lua_strlibopen(luaVM);
   lua_mathlibopen(luaVM);

   printf("Simple Functional lua interpreter\n");
   printf("Based on lua version 4.0.1\n");
   printf("Enter lua commands. type 'exit<enter>' to exit\n");
   printf("\n>");
 
   lua_dofile(luaVM, "startup.lua");
 
   lua_close(luaVM);
}
Startup.lua contains: -- Simple lua script -- comments indicated with a '--' a = 5; b = 10; c = a + b; print ("5+10=" .. c); I'm definatley including the correct libs, files..I just don't understand the error and why this is happening. If you need any more information don't hesitate to ask. Thank you, Mike
-Brcolow-
Is this a console program? If not, where would it be printing to?

Looking at the stack trace and vaguely remembering my past experiences with lua, I think that may be the problem (the print function). You may have to define your own print function.

It also appears that you are/have compiled lua as Managed code (.NET) rather than unmanaged code. I don't know if that could cause problems, but it certainly is a possibility.
Advertisement
There is a console window and a render window but when I took out the print function from the LUA script it worked. You were right, so how can I create my own print function?

Thank you.
-Brcolow-

This topic is closed to new replies.

Advertisement