lua-users home
lua-l archive

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

On Fri, Nov 26, 2010 at 12:05 PM, GrayFace <> wrote:
> Why? Dlls may rely on runtime dll version being the same only if they are
> packaged together. Otherwise, this is a bug in dll. This bug should be
> uncommon for Lua dlls, because Lua provides an allocator that solves the
> problem of passing memory between Lua dlls.

It is true that you can avoid linking your Lua extensions against the
runtime, if you _only_ use Lua's facilities for allocating memory:

See the very useful (but long) document:

(search for 'Avoiding linking to any C run-time library' - poor man's
wiki hyperlink ;))

#include <lua.h>
#include <lauxlib.h>
#include <windows.h>
BOOL APIENTRY DllMain(HANDLE module, DWORD reason, LPVOID reserved) {
return TRUE; }
static int l_messagebox(lua_State * L) {
  const char * s = luaL_checkstring(L, 1);
  MessageBox(NULL, s, "messagebox", MB_OK);
  return 0;
__declspec(dllexport) int luaopen_messagebox(lua_State * L) {
  lua_pushcfunction(L, l_messagebox);
  return 1;

It shows how to build this with gcc and cl, only 3Kb!

But, if it calls any C runtime functions, then that runtime's
allocator may kick in, and you are back where you started.

Most C extensions take the lazy way out and just use malloc (or
strdup, etc) - naturally they wish to remain portable!

steve d.