Advertisement

tolua++ and namespaces

Started by November 20, 2011 06:47 PM
0 comments, last by JoachimKlahr 13 years, 3 months ago
[font="arial, verdana, tahoma, sans-serif"]Hi,

I'm about to implement Lua support into my engine, but have stumbled upon a little problem that hopefully is pretty simple to solve.[/font]
I've been following this guide http://usefulgamedev...ua-example.html and it works without any issues. The problem is that all my engine classes is inside a namespace. So I tried to add a namespace around the Player class (in the example), and the files gets generated and the project still compiles. So to my question:

How do I create an instance of MyNameSpace::Player class in Lua?
#ifndef PLAYER_H
#define PLAYER_H

namespace MyNameSpace { // THIS IS ADDED BY ME!
class Player {
private:
int health;
public:
Player();
~Player();
void setHealth(int _health);
int getHealth();
};
}

#endif // PLAYER_H
[font="arial, verdana, tahoma, sans-serif"] [/font][font="arial, verdana, tahoma, sans-serif"]How should this file look like after I've added the namespace?[/font][font="arial, verdana, tahoma, sans-serif"] [/font]
-- Create new Player object and set health
player = Player:new()
player:setHealth(4)

-- Display players health
io.write("LUA: Player's health is "..player:getHealth());
[font="arial, verdana, tahoma, sans-serif"] [/font][font="arial, verdana, tahoma, sans-serif"]Thanks for your help! :)[/font]
http://epiccode.org/
Got it to work!This is what I did.Player.pkg$#include "Player.h"$using namespace MyNamespace;module MyNamespace{class Player { ...};}Then in the script I did like this:script.luaplayer = MyNamespace.Player:new()
http://epiccode.org/

This topic is closed to new replies.

Advertisement