Original Post
Good evening to all game programmers out there, I am currently trying to get in touch with LuaPlus. As I am german, and the rest of the world just only speaks english, my first try of learning Lua is to write a language wrapper. I know, I could even use something like XML, perhaps this makes more sense then the use of Lua, but I don't want [grin] So, this is my Lua source: This is the way to call LuaPlus functions in C++, as explained in the documentation, works fine. [totally] Here is my little class I've written. It only has a constructor, a desturctor and a method called Get, which returns a string. The (private) method Language should be accessable by all the class methods, but I have no clue how to do that, the code I have written produces a compiler error [tears]. I even thougt to bind the function everytime in the Get method, but if the class should grow, Language has to be bind in every method, that uses it. Has anyone an idea how to solve that? Greetings
--
-- English Language File
--
function language( code )
if ( code == "error_net" ) then
return "Network Error"
elseif ( code == "player_health" ) then
return "Health"
end
end
LuaPlus::LuaState *luaState = LuaPlus::LuaState::Create();
luaState->DoFile("english.lua");
LuaPlus::LuaFunction<const char*> Lang = luaState->GetGlobal("language");
printf("%s", Lang("error-net"));
LuaPlus::LuaState::Destroy(luaState);
class C_Language {
public:
std::string Get(const char *pcCode);
C_Language(std::string cFile);
~C_Language();
private:
LuaPlus::LuaState *luaState;
LuaPlus::LuaObject *luaObject;
LuaPlus::LuaFunction<const char*> *Language;
};
C_Language::C_Language(std::string cFile) {
LuaPlus::LuaState *luaState = LuaPlus::LuaState::Create();
luaState->DoFile(cFile.c_str());
LuaPlus::LuaFunction<const char*> Language = luaState->GetGlobal("language");
}
C_Language::~C_Language() {
LuaPlus::LuaState::Destroy(luaState);
}
std::string C_Language::Get(const char *pcCode) {
std::string cValue;
return cValue.append(Language(pcCode));
}