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

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
dracula004
Prole
Posts: 17
Joined: Tue Mar 03, 2015 2:50 am
Location: Asia

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

Post 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
Last edited by dracula004 on Fri May 15, 2015 1:22 am, edited 1 time in total.
github:https://github.com/Nigh

email:xianyi.xia#outlook.com
User avatar
SiENcE
Party member
Posts: 804
Joined: Thu Jul 24, 2008 2:25 pm
Location: Berlin/Germany
Contact:

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

Post 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.
User avatar
dracula004
Prole
Posts: 17
Joined: Tue Mar 03, 2015 2:50 am
Location: Asia

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

Post 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.
github:https://github.com/Nigh

email:xianyi.xia#outlook.com
User avatar
dracula004
Prole
Posts: 17
Joined: Tue Mar 03, 2015 2:50 am
Location: Asia

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

Post 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?
github:https://github.com/Nigh

email:xianyi.xia#outlook.com
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

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

Post 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.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
dracula004
Prole
Posts: 17
Joined: Tue Mar 03, 2015 2:50 am
Location: Asia

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

Post 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
github:https://github.com/Nigh

email:xianyi.xia#outlook.com
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

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

Post 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?
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
dracula004
Prole
Posts: 17
Joined: Tue Mar 03, 2015 2:50 am
Location: Asia

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

Post 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;
}
github:https://github.com/Nigh

email:xianyi.xia#outlook.com
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

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

Post by arampl »

Try rebuild dll with VS or QT Creator.
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

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

Post 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.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 3 guests