# Lua and Dev-C++

This topic is 2787 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 on other sites
For Dev-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 on other sites
thank you! it compiled. i can't actually test it yet though because i'm using HGE and there is no command line output.

##### Share on other sites
Good, now you should delete Dev-C++ off your drive and install something that doesn't suck.

##### Share on other sites
Quote:
 Original post by PromitGood, 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 on other sites
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 on other sites
Quote:
Original post by overeasy
Quote:
 Original post by PromitGood, 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 on other sites
If you really want a cross-platform IDE, there's Code::Blocks. You'll probably want to get a nightly build here, but you could get by with the old 8.02 release.

##### Share on other sites
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 on other sites
Quote:
 Original post by PromitEclipse 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 on other sites
Quote:
 Original post by overeasyand 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 on other sites
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 on other sites
Quote:
 Original post by overeasyshould 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 on other sites
Quote:
Original post by apefish
Quote:
 Original post by overeasyshould 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 on other sites
Quote:
 Original post by overeasyI agree this is a clean solution for the game data, but what about raw map files? IE0,1,0,21,5,2,60,1,2,35,1,2,3This 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 on other sites
Quote:
 Original post by overeasyi 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 overeasyno 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 on other sites
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 on other sites
Actually, wxDev-C++ is the new Dev-C++. It looks like it's still only for windows.

##### Share on other sites
Quote:
Original post by overeasy
Quote:
 Original post by PromitEclipse 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 on other sites
Quote:
Original post by apefish
Quote:
 Original post by overeasyI agree this is a clean solution for the game data, but what about raw map files? IE0,1,0,21,5,2,60,1,2,35,1,2,3This 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 on other sites
Quote:
Original post by ExcessNeo
Quote:
Original post by overeasy
Quote:
 Original post by PromitEclipse 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 on other sites
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 on other sites
Quote:
 Original post by MeshGearFoxI'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 on other sites
Quote:
Quote:
 Original post by MeshGearFoxI'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 on other sites

This topic is 2787 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628715
• Total Posts
2984360

• 24
• 11
• 10
• 13
• 14