summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--game.cpp7
-rw-r--r--game.h2
-rw-r--r--scripting.cpp8
-rw-r--r--scripting.h3
-rw-r--r--scripting/test.cpp7
-rw-r--r--scripting/test.h1
-rw-r--r--scripting/test.pkg1
7 files changed, 29 insertions, 0 deletions
diff --git a/game.cpp b/game.cpp
index d198720..42e8b53 100644
--- a/game.cpp
+++ b/game.cpp
@@ -10,12 +10,19 @@ Game* Game::game = NULL;
Game::Game() : socket(io_service) {
scene = new Scene();
+
+ scene->lua->set_say_func(boost::bind(&Game::say, this, _1));
}
Game::~Game() {
delete scene;
}
+void Game::say(const std::string msg) {
+ message::Message m(msg);
+ m.send(socket);
+}
+
void Game::run(const std::string host, const unsigned int port) {
run(host, boost::lexical_cast<std::string>(port));
}
diff --git a/game.h b/game.h
index 7b3ad55..44222c2 100644
--- a/game.h
+++ b/game.h
@@ -19,6 +19,8 @@ class Game {
Game();
~Game();
+ void say(const std::string msg);
+
void run(std::string host, unsigned int port);
void run(std::string host, std::string port);
diff --git a/scripting.cpp b/scripting.cpp
index ed671a2..520ee9d 100644
--- a/scripting.cpp
+++ b/scripting.cpp
@@ -27,6 +27,10 @@ void Lua::set_log_func(boost::function<void (const char*)> log_func) {
log_func("Lua::set_log_func() called");
}
+void Lua::set_say_func(boost::function<void (const char*)> say_func) {
+ this->say_func = say_func;
+}
+
void Lua::print(const char *s) {
if(log_func)
log_func(s);
@@ -34,6 +38,10 @@ void Lua::print(const char *s) {
std::cout << s << std::endl;
}
+void Lua::say(const char *s) {
+ say_func(s);
+}
+
void Lua::dostring(std::string s) {
int before = lua_gettop(L);
int err = luaL_dostring(L, s.c_str());
diff --git a/scripting.h b/scripting.h
index d14aa3c..4b0bacf 100644
--- a/scripting.h
+++ b/scripting.h
@@ -16,13 +16,16 @@ class Lua {
protected:
lua_State *L;
boost::function<void (const char*)> log_func;
+ boost::function<void (const char*)> say_func;
public:
Lua();
virtual ~Lua();
void set_log_func(boost::function<void (const char*)> log_func);
+ void set_say_func(boost::function<void (const char*)> say_func);
void print(const char *s);
+ void say(const char *s);
void dostring(std::string s);
};
diff --git a/scripting/test.cpp b/scripting/test.cpp
index 1a378b7..5ec27da 100644
--- a/scripting/test.cpp
+++ b/scripting/test.cpp
@@ -9,3 +9,10 @@ void print(lua_State *L, const char *s) {
lua_pop(L, 1);
lua->print(s);
}
+
+void say(lua_State *L, const char *s) {
+ lua_getglobal(L, "lua_instance");
+ Lua *lua = static_cast<Lua*>(lua_touserdata(L, -1));
+ lua_pop(L, 1);
+ lua->say(s);
+}
diff --git a/scripting/test.h b/scripting/test.h
index 48f560e..7ff5719 100644
--- a/scripting/test.h
+++ b/scripting/test.h
@@ -4,5 +4,6 @@
#include <lua.hpp>
void print(lua_State *L, const char *s);
+void say(lua_State *L, const char *s);
#endif
diff --git a/scripting/test.pkg b/scripting/test.pkg
index 38525c6..0f64be7 100644
--- a/scripting/test.pkg
+++ b/scripting/test.pkg
@@ -1,5 +1,6 @@
$hfile "scripting/test.h"
void print(lua_State *L, const char *s);
+void say(lua_State *L, const char *s);
// vim: syn=cpp