lua-users home
lua-l archive

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


You need Lua in a DLL in order to use it from multiple DLLs (or at least
that seems the simplest solution).

If you have Lua as libs that your are statically linking to each of the DLLs
then therein lies your problem.  The root of this problem is the manner of
linkage to the C libraries.  If a statically linked Lua lib in each DLL
statically links the C libraries then you will have multiple copies of the C
libraries and multiple copies of their associated run time state (such as
the heap).  If one of these instances of the C libraries tries to "return"
memory to its heap that was actually allocated by a different instance on a
different heap then poof your problem appears.

Technically I don't think you "need" to dynamically link Lua, but rather you
just need the Lua libs you are using to dynamically link the C run time
libraries.  However, the simplest way to do that under VC is to just build
it as a DLL.  Also, you don't need all of those extra copies of Lua anyway
and keeping them just complicates version control as having different
versions of Lua handing a lua_State back and forth is a BAD IDEA.


-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br]On Behalf Of Mihai Cozma
Sent: Tuesday, February 24, 2004 1:44 PM
To: lua mailing list
Subject: dll BIG LUA problem


hi. i'm trying to make something like this. i have a main application and a
lot
of dlls. i made my own load dll function and i load all dlls using
LoadLibrary
into my main app. then i get from each of this dll a function, using
GetProcAddress. then i run all this functions, their only parameter is a
lua_State pointer i've created in my main application as a global variable.
in
those functions i'm registering other functions into lua state. the problem
is
that when i'm doing it i get an error (a heap error). from the debuger i saw
that the error is produced by luaM_realloc, wich calls free(). so i guess is
because lua tries to delete something allocated in the app from the dll. so
i've identified the problem, but i need a solution to. as i didn't build lua
libs from the sources(but i got them too) i use the binaries provided from
lua.org. i've saw over www a method to solve, by modifing luaM_realloc with
some global allocation functions. is there any other solve, or i have to do
it
myself too, wich it doesn't sound like a good idea, cause it has some
trad-offs
too. please help.thanks

mihai



______________________________________________________________________
Do you want a free e-mail for life ? Get it at http://www.personal.ro/