Sign in to follow this  
overeasy

Lua and Dev-C++

Recommended Posts

overeasy    100
Hello all. I'm having trouble setting up Lua with Dev-C++ I saw that with the HGE game engine there are different library extensions for different compilers, and from what I understand, Dev-C++ has some strange native compiler. So how do I compile the Lua libraries for Dev-C++? I just this week started using C++ and external libraries. My last project was in Java from the ground up. EDIT: I think the problem is the difference between a ".lib" file and a ".a" file

Share this post


Link to post
Share on other sites
Drew_Benton    1861
For Dev-C++:

1. Add the Lua sources/header files to your project (from a Source download, not precompiled). However, do not any files that link a main though, such as lua.c or luac.c.

2. Go to Project->Project Options. Click the Files tab. For any .c file, remove the checkbox for Compile as C++.

3. You are ready to use Lua!

I just tested it with Dev-C++ 4.9.9.2 and Lua 5.1.4 and it worked fine.

Here's a simple test program you can use to make sure you got it working right:


#include <cstdlib>
#include <iostream>

extern "C" {
#include "lua/lua.h"
#include "lua/lualib.h"
#include "lua/lauxlib.h"
}

using namespace std;

int main(int argc, char *argv[])
{
lua_State * L = lua_open();
luaL_openlibs(L);
luaL_dostring(L, "print(\"Hello World from Lua!\")");
lua_close(L);
system("PAUSE");
return EXIT_SUCCESS;
}




The project folder would look like this:

Share this post


Link to post
Share on other sites
overeasy    100
Quote:
Original post by Promit
Good, now you should delete Dev-C++ off your drive and install something that doesn't suck.


no microsoft products please. i used eclipse for java but dev-c++ looked like the beginner standard.

Share this post


Link to post
Share on other sites
overeasy    100
and now for some actual lua related questions:

should my xml map parser be in lua or c++?

are there any other libraries that would make the production of a full game easier?

i'm using c++, haaf's game engine, and lua.

do any sort of database languages make sense to use?
i'm not looking to do any networking any time soon (plus every complains that networked games should be built from the ground up FOR networking).

Share this post


Link to post
Share on other sites
Ariste    296
Quote:
Original post by overeasy
Quote:
Original post by Promit
Good, now you should delete Dev-C++ off your drive and install something that doesn't suck.


no microsoft products please. i used eclipse for java but dev-c++ looked like the beginner standard.

Why not? Visual Studio is the best IDE around for Windows, and you can get the Express Edition for free.

Share this post


Link to post
Share on other sites
Promit    13246
Eclipse also has C++ support. Not sure how the CDT is nowadays, but it can't possibly be a worse choice than Dev-C++. Though frankly it's a pretty blockheaded idea to use anything other than VS on Windows unless you really can't.

Share this post


Link to post
Share on other sites
overeasy    100
Quote:
Original post by Promit
Eclipse also has C++ support. Not sure how the CDT is nowadays, but it can't possibly be a worse choice than Dev-C++. Though frankly it's a pretty blockheaded idea to use anything other than VS on Windows unless you really can't.


except for refactoring, i don't need the additional functionality. maybe eventually, but i am happy as is. i have lua confirmed working and can proceed with my coding. i'd use visual c++ if i was creating a windows app - instead i'm using a game engine library.

Share this post


Link to post
Share on other sites
overeasy    100
Quote:
Original post by overeasy
and now for some actual lua related questions:

should my xml map parser be in lua or c++?

are there any other libraries that would make the production of a full game easier?

i'm using c++, haaf's game engine, and lua.

do any sort of database languages make sense to use?
i'm not looking to do any networking any time soon (plus every complains that networked games should be built from the ground up FOR networking).


bump

Share this post


Link to post
Share on other sites
jyk    2094
Quote:
i'd use visual c++ if i was creating a windows app - instead i'm using a game engine library.
That doesn't really make sense as a reason not to use VC++. You can create pretty much any kind of application you want (and use pretty much any engine or library you want) with VC++.

Share this post


Link to post
Share on other sites
apefish    176
Quote:
Original post by overeasy
should my xml map parser be in lua or c++?


If you're going to have Lua, don't even bother with XML.
Lua was actually designed partially as a data description language, and is very nice for this purpose. I would go so far as to say that Lua is superior to XML for non-document data.

Just as an example of how to do this, consider a map for a text adventure type game:
In XML:

<map name = "twistymaze">
<room>
<description>you are in a maze of twisty little passages, all alike.</description>
</room>
<room>
<description>you are in a twisty little maze of passages, all alike.</description>
</room>
</map>


In Lua:

twistymaze = map{
room{description = "you are in a maze of twisty little passages, all alike."},
room{description = "you are in a twisty little maze of passages, all alike."}
}


The Idea is that you make your data file as a lua program that constructs whatever data you need as tables and so on. Note that 'map' and 'room' are functions that might do some processing on the tables they are given, like error checking, etc.

The book 'Programming In Lua' is a good read, and will give you more info on this idea. The old one is available on-line free, the new one you can buy (They arent much different, only buy if serious).

Share this post


Link to post
Share on other sites
overeasy    100
Quote:
Original post by apefish
Quote:
Original post by overeasy
should my xml map parser be in lua or c++?


If you're going to have Lua, don't even bother with XML.
Lua was actually designed partially as a data description language, and is very nice for this purpose. I would go so far as to say that Lua is superior to XML for non-document data.

Just as an example of how to do this, consider a map for a text adventure type game:
In XML:

<map name = "twistymaze">
<room>
<description>you are in a maze of twisty little passages, all alike.</description>
</room>
<room>
<description>you are in a twisty little maze of passages, all alike.</description>
</room>
</map>


In Lua:

twistymaze = map{
room{description = "you are in a maze of twisty little passages, all alike."},
room{description = "you are in a twisty little maze of passages, all alike."}
}


The Idea is that you make your data file as a lua program that constructs whatever data you need as tables and so on. Note that 'map' and 'room' are functions that might do some processing on the tables they are given, like error checking, etc.

The book 'Programming In Lua' is a good read, and will give you more info on this idea. The old one is available on-line free, the new one you can buy (They arent much different, only buy if serious).


I agree this is a clean solution for the game data, but what about raw map files? IE

0,1,0,2
1,5,2,6
0,1,2,3
5,1,2,3

This is where I was planning on using XML (the implementation was trivial in java)

Share this post


Link to post
Share on other sites
apefish    176
Quote:
Original post by overeasy

I agree this is a clean solution for the game data, but what about raw map files? IE

0,1,0,2
1,5,2,6
0,1,2,3
5,1,2,3

This is where I was planning on using XML (the implementation was trivial in java)


Is this some output from another program? ie. are you bound to use comma separated values (CSV) syntax for some reason? If so, that's not XML syntax any more than it is Lua syntax. If you have a bunch of data in that form, you can use sed or something to turn it into a friendlier format.

For a raw rectangle array map file, i would do:

map = {
{0,1,0,2},
{1,5,2,6},
{0,1,2,3},
{5,1,2,3},
}

which can then be indexed like map[row][column]. eg map[2][3]==2

Note that all I did was cut and paste that thing and put braces around it.

Share this post


Link to post
Share on other sites
mightshade    100
Quote:
Original post by overeasy
i used eclipse for java but dev-c++ looked like the beginner standard.

It was, many years ago. By now, it's just horribly outdated. I've found an article that explains it a little more in depth. Hope that helps.

Quote:
Original post by overeasy
no microsoft products please.

I hope that's not because of some antipathy towards Microsoft (that sentence looks like that), because you'd miss a really excellent tool just because it is made by the "wrong" company.

Share this post


Link to post
Share on other sites
trasseltass    123
Code:Blocks is the "new" Dev-C++. As the article states: Dev-C++ is no longer being maintained. If you want to work with the same IDE on multiple platforms, go with Code:Blocks.

Share this post


Link to post
Share on other sites
ExcessNeo    619
Quote:
Original post by overeasy
Quote:
Original post by Promit
Eclipse also has C++ support. Not sure how the CDT is nowadays, but it can't possibly be a worse choice than Dev-C++. Though frankly it's a pretty blockheaded idea to use anything other than VS on Windows unless you really can't.


except for refactoring, i don't need the additional functionality. maybe eventually, but i am happy as is. i have lua confirmed working and can proceed with my coding. i'd use visual c++ if i was creating a windows app - instead i'm using a game engine library.


Except when you do need the extra functionality you wont know where to start with Visual Studio because you will have never used it before.

Also I have news for you, if your planning on releasing your game on Windows you are creating a windows app.

Share this post


Link to post
Share on other sites
overeasy    100
Quote:
Original post by apefish
Quote:
Original post by overeasy

I agree this is a clean solution for the game data, but what about raw map files? IE

0,1,0,2
1,5,2,6
0,1,2,3
5,1,2,3

This is where I was planning on using XML (the implementation was trivial in java)


Is this some output from another program? ie. are you bound to use comma separated values (CSV) syntax for some reason? If so, that's not XML syntax any more than it is Lua syntax. If you have a bunch of data in that form, you can use sed or something to turn it into a friendlier format.

For a raw rectangle array map file, i would do:

map = {
{0,1,0,2},
{1,5,2,6},
{0,1,2,3},
{5,1,2,3},
}

which can then be indexed like map[row][column]. eg map[2][3]==2

Note that all I did was cut and paste that thing and put braces around it.


Alright. I'm writing from the ground up again so I don't have any data format that I need to preserve. You're right, I guess I might as well use Lua for the maps too.

Share this post


Link to post
Share on other sites
overeasy    100
Quote:
Original post by ExcessNeo
Quote:
Original post by overeasy
Quote:
Original post by Promit
Eclipse also has C++ support. Not sure how the CDT is nowadays, but it can't possibly be a worse choice than Dev-C++. Though frankly it's a pretty blockheaded idea to use anything other than VS on Windows unless you really can't.


except for refactoring, i don't need the additional functionality. maybe eventually, but i am happy as is. i have lua confirmed working and can proceed with my coding. i'd use visual c++ if i was creating a windows app - instead i'm using a game engine library.


Except when you do need the extra functionality you wont know where to start with Visual Studio because you will have never used it before.

Also I have news for you, if your planning on releasing your game on Windows you are creating a windows app.


I don't need to argue over this.

Share this post


Link to post
Share on other sites
MeshGearFox    158
Just to chime in about the IDE thing, I'm not going to say that any IDE is inherently better than any other IDE, but I will say that Dev-C++ was sort of weird to get APIs and libraries and things working in unless you used the Dev-Pak system, and those were... down or out of date half the time.

Anyway, in terms of bindings, I couldn't figure out whatever libraries I was trying to use because they weren't precompiled. I'm not even sure what bindings are anymore, although if I remember correctly it involved calling lua functions from C++?

This is probably wrong or inefficient or something but for calling lua functions from within C++ I just do:


error = luaL_loadfile(LuaVM, "input_values.lua") ||
lua_pcall (LuaVM, 0, 0, 0);

if(error) {
fprintf (stderr, "%s: %s\n", "input_values.lua", lua_tostring (LuaVM, -1));
lua_pop (LuaVM, 1);
}

...

snprintf(buffer, LUA_BUFFER_LENGTH, "period(%i)", myInst);
error = luaL_loadbuffer(LuaVM, buffer, strlen(buffer), "period") ||
lua_pcall(LuaVM, 0, 0, 0);
if(error) {
fprintf (stderr, "%s", lua_tostring (LuaVM, -1));
lua_pop (LuaVM, 1);
}



Again, not sure if that's actually right or not, but it's worked for me so far.

Share this post


Link to post
Share on other sites
jbadams    25676
Quote:
Original post by MeshGearFox
I'm not going to say that any IDE is inherently better than any other IDE
An IDE last updated in 2005 with 340 known bugs that will never be fixed is worse than most other IDEs. In this case it's not just a matter of preference: Dev-C++ is objectively bad when compared to other available options such as Code::Blocks, Visual Studio Express Editions or wxDev-C++.

However, the point has already been made, so I'm going to ask that unless overeasy asks a question directly pertaining to his choice of IDE everyone let the matter drop and stick to answering the questions at hand in this thread.

Share this post


Link to post
Share on other sites
overeasy    100
Quote:
Original post by jbadams
Quote:
Original post by MeshGearFox
I'm not going to say that any IDE is inherently better than any other IDE
An IDE last updated in 2005 with 340 known bugs that will never be fixed is worse than most other IDEs. In this case it's not just a matter of preference: Dev-C++ is objectively bad when compared to other available options such as Code::Blocks, Visual Studio Express Editions or wxDev-C++.

However, the point has already been made, so I'm going to ask that unless overeasy asks a question directly pertaining to his choice of IDE everyone let the matter drop and stick to answering the questions at hand in this thread.


common misconception: i actually fixed all those bugs and recompiled it for personal use. also, i do frequently use traditional microsoft ides such as notepad and wordpad.

as for lua, i have it completely working and am making great pace in integrating it to my game environment (thanks to post #2). no further questions (i'll start a more specific thread in the future if need be).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this