I managed to get lua embedded into my app, now I want to make it compatible with C++. After trying many different libraries I decided on using Lunar because it's lightweight being made of a single header file (that, and all the other libraries didn't work).
I got the header and followed the example from here.
I took one of my pre-existing classes and added some lua friendly functions so now it looks like this:
When I declare this class in main.cpp, I get an error that says "error: no matching function for call to 'game::game()' ". Now I know that I'm getting it because the class is trying to call it's constructor, but something is going wrong. In my example I declared the constructor as "game(lua_State *L)" and the error says it's looking for "game()", but if I declare it as "game()" then the error is "error: no matching function for call to 'game::game(lua_State*&)' ". What I'm getting from this is that I need to declare "game()" and "game(lua_State*L)", but that would create a new error due to declaring the same function twice, and that is why I'm stuck.
I have been following the example on the page I linked above, unfortunately there is no documentation for Lunar besides this one page and google is giving me flikr pictures for some reason. Does anyone have experience with Lunar or using C++ and lua together? I would really like to know what I'm doing wrong.
I got the header and followed the example from here.
I took one of my pre-existing classes and added some lua friendly functions so now it looks like this:
Code:
#include "lunar.h"
class game
{
private:
// the window resolution
int resWidth, resHeight;
// fullscreen or not? 0 for windowed, 1 for full
bool fullscreen;
// 2D or 3D? 0 for 2D, 1 for 3D
bool perspective;
public:
// register lua functions
static const char className[];
static Lunar<game>::RegType methods[];
SDL_Surface *gScreen;
game(lua_State *L) {resWidth = 1280; resHeight = 800; fullscreen = 0; perspective = 0;}
void createSurface();
void Init();
void Reshape();
void Cleanup();
int changeRes(lua_State *L);
int changeFull(lua_State *L);
int changePers(lua_State *L);
~game();
};
When I declare this class in main.cpp, I get an error that says "error: no matching function for call to 'game::game()' ". Now I know that I'm getting it because the class is trying to call it's constructor, but something is going wrong. In my example I declared the constructor as "game(lua_State *L)" and the error says it's looking for "game()", but if I declare it as "game()" then the error is "error: no matching function for call to 'game::game(lua_State*&)' ". What I'm getting from this is that I need to declare "game()" and "game(lua_State*L)", but that would create a new error due to declaring the same function twice, and that is why I'm stuck.
I have been following the example on the page I linked above, unfortunately there is no documentation for Lunar besides this one page and google is giving me flikr pictures for some reason. Does anyone have experience with Lunar or using C++ and lua together? I would really like to know what I'm doing wrong.