lua-users home
lua-l archive

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

On 27/11/2010, at 8:59 PM, GrayFace wrote:

> That's why it's called internal :) Modules shouldn't access it directly, because it may be affected by fields aligning settings.

Of course they shouldn't access it. But I am saying that if the app creates a lua_State (v5.2) pointer and then calls (say) luasocket, and luasocket thinks the lua_State pointer (which C functions get given) is a v5.1 pointer, then you get the crash.

> Adding the version number into module name is a bad idea, but it would be good to add an exported function that would return the Lua version that the module was compiled against

All this does is detect you are using the wrong DLL. It doesn't solve finding the correct one.

On 27/11/2010, at 12:22 PM, Luiz Henrique de Figueiredo wrote:
> This already happens because several symbols in Lua 5.1 are abssent in Lua 5.2
> (but are supported via macros). For instance, luaL_register and lua_tonumber.

I noticed that. And indeed it stops the main app loading the wrong Lua DLL.

Let me try to explain with a simplified example, not using real-world function names.

Main app: Initialize Lua (grabs Lua 5.2 DLL) - success!

Main app: Runs a script supplied by the user (note, scripting languages encourage user scripts)

Script:  require "luasocket"   (grabs luasocket.DLL compiled for Lua 5.1)
 (note - luasocket.DLL finds Lua5.1.DLL which it is linked against somewhere in the Windows $PATH - not that unlikely)

Script: somevar = luasocket.http_open ("";)

Lua (v5.2): is only interested in resolving the entry point http_open in the loaded luasocket DLL. Success!

Lua (v5.2): calls C function http_open passing the Lua 5.2 state to a C function compiled for a 5.1 state

Crash! (internal contents of Lua 5.2 state is different to what the Lua 5.1 code that luasocket.DLL uses is expecting).

All this would be resolved if we had instead:

require "luasocket.5.2"

After all, the code only will work with this DLL (the luasocket DLL specifically compiled for Lua 5.2).

That forces Lua to pull in the luasocket DLL intended for this version of Lua. It won't grab a luasocket for Lua 5.1 (which won't work) or Lua 5.3 (which also won't work one day in the future).