Almost have my own library to use with LOVE! Help needed.

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
Zorbatron
Citizen
Posts: 78
Joined: Wed May 27, 2009 6:58 pm

Almost have my own library to use with LOVE! Help needed.

Post by Zorbatron » Tue Jul 14, 2009 12:43 am

Sorry for all the consent questions, hopefully this will be the last of them, I appreciate the help

Pretty much, I don't know how to make an extension library with LOVE. I don't want to have to recompile LOVE source in order to make an extension.

Attached are the files I'm running with. Source to my dll, and the lua5.1.lib library, and my VS 2008 proj file. I compiled from the luabinaries source page. (lua 5.1.4, standard stuff).

The error I'm getting when I run:

Code: Select all

require("luatestdll");

function load()
	print("hi");
end
is this:

Code: Select all

error loading module 'luatestdll' from file 'C:\Program Files\LOVE\luatestdll.dll':
	The specified procedure could not be found.


stack traceback:
	[C]: ?
	[C]: in function 'require'
	[string "main.lua"]:1: in main chunk
Attachments
lua5.1-dll-proj.rar
My lua5.1.lib compiled as c++ (doesn't have to be just is),vs 2008 proj file, and dll source.
(245.92 KiB) Downloaded 107 times

User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Almost have my own library to use with LOVE! Help needed.

Post by bartbes » Tue Jul 14, 2009 6:58 am

The error looks like you forgot to export the luaopen_luatestdll function.

User avatar
Zorbatron
Citizen
Posts: 78
Joined: Wed May 27, 2009 6:58 pm

Re: Almost have my own library to use with LOVE! Help needed.

Post by Zorbatron » Tue Jul 14, 2009 3:43 pm

Got it to work!!!!!!!!!!! Haha!

I went about trying to understand the process of loading a library and running a function from it. My simplest example was:
testdllcall.cpp

Code: Select all

#include <iostream>
#include <windows.h>

typedef char* (__stdcall *pProtoFunc)(void);

void PrintErrCode(DWORD err)
{

	// Translate ErrorCode to String.
	LPTSTR Error = 0;
	if(FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
						NULL,
						err,
						0,
						(LPTSTR)&Error,
						0,
						NULL) == 0)
	{
	   wprintf(L"Unable to translate error code");
	}
	wprintf(L"Error: %s\n",Error);

}

void CallLib(char* strbuf)
{
	HINSTANCE DLLID = LoadLibrary(L"C:\\testdll.dll");

	FARPROC ProcID = GetProcAddress(HMODULE(DLLID),"testfunction");



	if (!ProcID)
	{
		PrintErrCode(GetLastError());
		return;
	}

	pProtoFunc func;
	func = pProtoFunc(ProcID);
	memcpy(strbuf,func(),3);

	FreeLibrary(DLLID);
}

int main()
{
	char buf[3];
	CallLib(buf);
	std::cout<<buf<<std::endl;
	std::system("pause");
	return 0;
}
testdll.dll

Code: Select all

char* testfunction()
{
	return "yo";
}
Running that would give me the same error "Specified procedure could not be found".

But then, I figured out if you change testdll.dll to this:

Code: Select all

#include <iostream>

extern "C" __declspec(dllexport) char* testfunction()
{
	return "yo";
}
It got rid of the error and printed "yo"!

I did the same with my code for LOVE dll and it worked! The function was pushed onto the lua stack! A good day indeed.

User avatar
osgeld
Party member
Posts: 303
Joined: Sun Nov 23, 2008 10:13 pm

Re: Almost have my own library to use with LOVE! Help needed.

Post by osgeld » Tue Jul 14, 2009 5:38 pm

course you know using dll's limit anything you write to windows

User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Almost have my own library to use with LOVE! Help needed.

Post by bartbes » Tue Jul 14, 2009 8:10 pm

True, but the process is almost the same on linux (and I guess mac), the biggest difference is the lack of a need to export the symbols. Oh, and I should've known about the extern "C" part..

User avatar
Zorbatron
Citizen
Posts: 78
Joined: Wed May 27, 2009 6:58 pm

Re: Almost have my own library to use with LOVE! Help needed.

Post by Zorbatron » Wed Jul 15, 2009 1:43 am

osgeld wrote:course you know using dll's limit anything you write to windows
w3schools wrote: Windows XP is the most popular operating system. The Windows family counts for about 90% [of all users].
Source:
w3schools.com OS Usage Table

Turns out that's not such a bad thing ;)

W3schools is an extremely popular site for learning all things web-based, like HTML, CSS, SQL, ect. Bottom line, they get a lot of visitors so their statistics are accurate.

TacticalPenguin
Prole
Posts: 15
Joined: Thu Dec 11, 2008 5:44 am

Re: Almost have my own library to use with LOVE! Help needed.

Post by TacticalPenguin » Wed Jul 15, 2009 2:06 am

W3schools' demographic is a bit different from the demographic of programmers who hang out on forums (the kind of people who will actually download things made with love)

The demographic that hangs out on this forum includes people who only use linux and don't even have a windows install; thus it can be a bad thing; love is crossplatform for a reason, unless it is simply impossible you should try to keep any additions you have for it crossplatform as well. For personal development purposes I suppose it works, but really, throwing out 10% of your worldwide audience (and probably more than that percentage in your realistic audience) is rarely a good idea if it can be avoided.

User avatar
osgeld
Party member
Posts: 303
Joined: Sun Nov 23, 2008 10:13 pm

Re: Almost have my own library to use with LOVE! Help needed.

Post by osgeld » Wed Jul 15, 2009 2:27 am

TacticalPenguin wrote:The demographic that hangs out on this forum includes people who only use linux and don't even have a windows install
yep, its a pretty safe bet to say that the majority of people here do not have windows, I dont, i have linux and a dual 1ghz g4 (my new freebe toy)

windows is becoming more and more that OTHER guy thats a propitiatory pita to deal with, not on a vast scale but it is slowly happening, especially on indy software development, why spend a good chunk of change on VS and make windows only code when the tools are available for free to more or less be accessible to everyone.
Last edited by osgeld on Wed Jul 15, 2009 2:30 am, edited 1 time in total.

User avatar
Zorbatron
Citizen
Posts: 78
Joined: Wed May 27, 2009 6:58 pm

Re: Almost have my own library to use with LOVE! Help needed.

Post by Zorbatron » Wed Jul 15, 2009 2:28 am

TacticalPenguin wrote:W3schools' demographic is a bit different from the demographic of programmers who hang out on forums (the kind of people who will actually download things made with love)

The demographic that hangs out on this forum includes people who only use linux and don't even have a windows install; thus it can be a bad thing; love is crossplatform for a reason, unless it is simply impossible you should try to keep any additions you have for it crossplatform as well. For personal development purposes I suppose it works, but really, throwing out 10% of your worldwide audience (and probably more than that percentage in your realistic audience) is rarely a good idea if it can be avoided.
Why is my audience that of the LOVE community? If I am making a game, my target is the world, not the LOVE community. If I want to make an extension, API, or framework for other people to use, I will make it crossplatform. If I want to make a game to distribute via some portal, or likely my own website (aka end product), I really don't care much for crossplatform support unless people request it. Honestly, if you have Linux, you should install windows as well, windows isn't big, and there's alot of reasons you should use it (the number one reason being its mainstream and is the most compatible with indie projects).

TacticalPenguin
Prole
Posts: 15
Joined: Thu Dec 11, 2008 5:44 am

Re: Almost have my own library to use with LOVE! Help needed.

Post by TacticalPenguin » Wed Jul 15, 2009 3:10 am

osgeld - I wouldn't say the majority around here don't have windows but I think it is certainly more than 10%
Zorbatron wrote:Why is my audience that of the LOVE community? If I am making a game, my target is the world, not the LOVE community. If I want to make an extension, API, or framework for other people to use, I will make it crossplatform. If I want to make a game to distribute via some portal, or likely my own website (aka end product), I really don't care much for crossplatform support unless people request it. Honestly, if you have Linux, you should install windows as well, windows isn't big, and there's alot of reasons you should use it (the number one reason being its mainstream and is the most compatible with indie projects).
You make a fair point that the world is your audience when distributing by other channels (but I've yet to see any love games make it that far), but ditching linux/mac because they make up only 10% (if your audience is the world then that's actually a hell of a lot of people) of your potential userbase is (in my opinion) ridiculous. If someone has to pay $100+ for an OS that rarely works as well as what they've got is just to play a game that has potential to work on their native OS, they're not going to play the game. You'd only be contributing to the only reason why many programmers have windows which is to play games because nobody bothers to make things work with linux/osx; in this case love works fine on linux/osx so I would at least put forth some decent effort to find a way to make your potential game stay that way as well.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 9 guests