lua-users home
lua-l archive

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


Another (possibly related) bug is this: if you load dll1 and after
that dll2 (regardless if you unload dll1 first) which both export a
function with the same name, only dll1.func() gets called even if I
try dll2.func().

Test case:

require 'alien'

local dll1,dll2='dll1.dll','dll2.dll'
local libs = setmetatable({}, {__mode='k'})

function test(libname,fname,should_be)
	local lib = alien.load(libname)
	libs[lib] = true
	lib[fname]:types{abi='stdcall',ret=i}
	print(lib, fname..'() -> ', lib[fname](),'should be',should_be)
	alien.loaded[libname] = nil
	collectgarbage('collect')
end

test('dll1.dll','test',1)
test('dll2.dll','test',2)

test('dll1.dll','test1',1)
test('dll2.dll','test2',2)

print(next(libs) and 'libs still hanging' or 'all libs garbage-collected')
for lib in pairs(libs) do
	print('',lib)
end


Output:


>lua "test_dll2.lua"
alien library dll1.dll	test() -> 	1	should be	1
alien library dll2.dll	test() -> 	1	should be	2
alien library dll1.dll	test1() -> 	1	should be	1
alien library dll2.dll	test2() -> 	2	should be	2
libs still hanging
	alien library ĐBA
	alien library dll2.dll
>Exit code: 0    Time: 0.217


For this example you need to build 2 dlls. I did it in Delphi
(freepascal should compile this too in Delphi mode):

----------------------- file dll1.dpr -----------------------

library dll1;

uses
  SysUtils,
  Classes;

{$R *.res}

function test: integer; stdcall;
begin
  result := 1;
end;

function test1: integer; stdcall;
begin
  result := 1;
end;

exports
  test,
  test1;

begin

end.

----------------------- file dll2.dpr -----------------------

library dll2;

uses
  SysUtils,
  Classes;

{$R *.res}

function test: integer; stdcall;
begin
  result := 2;
end;

function test2: integer; stdcall;
begin
  result := 2;
end;

exports
  test,
  test2;

begin

end.