Page 1 of 4

[SOLVED]HELP! How to make a dll available for Love2D ?

Posted: Fri Apr 03, 2015 7:54 am
by dracula004
** solved there:viewtopic.php?f=4&t=79958&start=30#p184197

:cool:

I'm trying to make a dll write by C available for Love2D.

There are some problems. I required the dll in lua5.1.4, it works well..

But when I require it in love2d, it crashed. :death:

the dll for test will be attached.
libtest514.7z
(38.21 KiB) Downloaded 166 times
help me plz~ :3

lua code:

Code: Select all

lib=require("libtest514")
print(lib.doubles(123))

lua in love2d code:

Code: Select all

function love.load()
	lib=require("libtest514")
end

_dt=0
function love.update(dt)
  _dt=dt
end

function love.draw()
  love.graphics.printf(_dt, 1, 1,1)
end

Re: HELP! How to make a dll available for Love2D ?

Posted: Fri Apr 03, 2015 11:26 am
by SiENcE
Here is a project of me that uses a dll in a löve project.

https://github.com/SiENcE/lovemidi

If you have a 32bit dll, you have to use the 32bit löve runtime. If you have a 64bit dll, you have to use the 64bit löve runtime.

Re: HELP! How to make a dll available for Love2D ?

Posted: Sat Apr 04, 2015 4:42 am
by dracula004
SiENcE wrote:Here is a project of me that uses a dll in a löve project.

https://github.com/SiENcE/lovemidi

If you have a 32bit dll, you have to use the 32bit löve runtime. If you have a 64bit dll, you have to use the 64bit löve runtime.
thx much. I'll try it.

Re: HELP! How to make a dll available for Love2D ?

Posted: Sat Apr 04, 2015 7:14 am
by dracula004
SiENcE wrote:Here is a project of me that uses a dll in a löve project.

https://github.com/SiENcE/lovemidi

If you have a 32bit dll, you have to use the 32bit löve runtime. If you have a 64bit dll, you have to use the 64bit löve runtime.
I downloaded your project and tested it. It works well.
But I still don't know how to build a dll which is compatible with LOVE2D.
btw,I know how to build a dll for lua, are they different?

Re: HELP! How to make a dll available for Love2D ?

Posted: Sat Apr 04, 2015 12:54 pm
by s-ol
dracula004 wrote:
SiENcE wrote:Here is a project of me that uses a dll in a löve project.

https://github.com/SiENcE/lovemidi

If you have a 32bit dll, you have to use the 32bit löve runtime. If you have a 64bit dll, you have to use the 64bit löve runtime.
I downloaded your project and tested it. It works well.
But I still don't know how to build a dll which is compatible with LOVE2D.
btw,I know how to build a dll for lua, are they different?
Is your DLL x64 or x32? As SiENce said, it needs to match the LÖVE version you are running.

Re: HELP! How to make a dll available for Love2D ?

Posted: Tue Apr 07, 2015 1:38 am
by dracula004
S0lll0s wrote:
dracula004 wrote:
SiENcE wrote:Here is a project of me that uses a dll in a löve project.

https://github.com/SiENcE/lovemidi

If you have a 32bit dll, you have to use the 32bit löve runtime. If you have a 64bit dll, you have to use the 64bit löve runtime.
I downloaded your project and tested it. It works well.
But I still don't know how to build a dll which is compatible with LOVE2D.
btw,I know how to build a dll for lua, are they different?
Is your DLL x64 or x32? As SiENce said, it needs to match the LÖVE version you are running.

both are x32.

I read the source code of luamidi.
then I bulid a new dll in Code::Blocks with GCC(MinGW). The C::B project will be attached below.

As always, it works well in lua, but crashes in love2d. wtf?

HELP, plz...QAQ

C::B dll project:
lovedoubles.7z
(137.5 KiB) Downloaded 186 times
code for test:
in lua:

Code: Select all

lib=require("lovelib")
print(lib.doubles(123456))
in love2d:

Code: Select all

function love.load()
	lib=require("lovelib")
end
_dt=0
function love.update(dt)
  _dt=dt
end
function love.draw()
  love.graphics.printf(lib.doubles(_dt), 1, 1,1)
end

Re: HELP! How to make a dll available for Love2D ?

Posted: Tue Apr 07, 2015 9:25 am
by zorg
just a shot in the dark, but, from the code i saw, in plain lua, you passed an integer into the function defined by the dll, but in löve, you're passing in a floating point. perhaps this is the issue?

Re: HELP! How to make a dll available for Love2D ?

Posted: Tue Apr 07, 2015 9:31 am
by dracula004
zorg wrote:just a shot in the dark, but, from the code i saw, in plain lua, you passed an integer into the function defined by the dll, but in löve, you're passing in a floating point. perhaps this is the issue?
that's not the point. even I don't need to call the function in the dll, when I require the dll, love2d will crash.

and the source code of the doubles function are shown below:

Code: Select all

static int love_doubles (lua_State *L)
{
    double d = lua_tonumber(L, 1);
	d = d*2;
	lua_pushnumber(L, d);
	return 1;
}

Re: HELP! How to make a dll available for Love2D ?

Posted: Tue Apr 07, 2015 9:37 am
by arampl
Try rebuild dll with VS or QT Creator.

Re: HELP! How to make a dll available for Love2D ?

Posted: Tue Apr 07, 2015 9:37 am
by s-ol
Maybe you are building The DLL for an incompatible lua version? Löve is Lua 5.1 / Luajit, your "regular" lua might be 5.2.