2

I'm trying to load a chunk of Lua from some text not stored on the file system. I added an element to package.loaders to do this from C. As soon as I call lua_load, in C, to load/execute the chunk, the application aborts, crashes, no exception was raised. The app is gone.

This is a pretty big problem. Right now I'm trying to debug this one problem, but what happens if this happens in production for real? I must be missing something. How do we write quality, production code without LuaJIT aborting the app? I'm missing something. What am I missing?

A related SO article suggested running the app with regular Lua. I did it and it worked fine. So something in LuaJIT doesn't like my code. I can't find it.

I may be asking two questions:

  • How to find the specific problem with this particular code right now. Works in regular Lua, fails in LuaJIT.

  • How do we use LuaJIT so that when it hits something it doesn't like, that it won't completely abort the entire process?

The crash in LuaJIT is in lib_package.c at lua_call(L, 1, 1); /* run loaded module */ which is around line 431.

Community
  • 1
  • 1
101010
  • 14,866
  • 30
  • 95
  • 172
  • 1
    Did you run it in plain Lua _with API checking enabled?_ Lua will let you misuse the C API in ways that LuaJIT doesn't, but should pick the issues up if you enable API checking. – Colonel Thirty Two Nov 01 '14 at 02:51
  • Thanks! That did it. I had an extra call to lua_pop() in my code. – 101010 Nov 01 '14 at 03:40
  • How do we tell LuaJIT not to totally abort the entire app when it finds something it doesn't like? Or is this not a problem once you get the C API set and compiled? – 101010 Nov 01 '14 at 03:41
  • Aborting (or crashing) the entire application is a reasonable response to a programmer error, so that the developer is forced to find and fix the bug. And apparently it works well! LuaJIT has API checking as well, btw. Look for `LUA_USE_APICHECK` in the LuaJIT Makefile ... – siffiejoe Nov 01 '14 at 10:41
  • 1
    No it isn't. An exception is a reasonable response. An exception is like saying, "Hey, here's a problem, can you handle it now? If not, unhandled exception and app crash" vs "App Crash " and then the programmer has to spend hours scratching head. – 101010 Nov 01 '14 at 13:20
  • C doesn't have exceptions. Even in C++, underflows are still considered undefined behavior and will likely either trigger a segfault or break your program in other ways. API checking is disabled by default, because it's slow, and well-formed programs and libraries don't need it. – Colonel Thirty Two Nov 01 '14 at 13:41

0 Answers0