summaryrefslogtreecommitdiff
path: root/src/luascript.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2014-09-05 19:57:14 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2014-09-05 19:57:14 +0200
commit4ae6300717a10c7fa850b800f18a730aee1d3e07 (patch)
tree455ae17634f5bbd8b18ce3a256db2647853bd600 /src/luascript.cc
parentf4b015398462fff1a64d70b632390b4f06fe3bbe (diff)
Internal code editor. Sound system.
Diffstat (limited to 'src/luascript.cc')
-rw-r--r--src/luascript.cc99
1 files changed, 93 insertions, 6 deletions
diff --git a/src/luascript.cc b/src/luascript.cc
index df607de..ecbed53 100644
--- a/src/luascript.cc
+++ b/src/luascript.cc
@@ -58,9 +58,9 @@ static int _forward(lua_State *L)
Pracro::T_STRING,
Pracro::T_END);
*/
- int x = lua_tonumber(L, lua_gettop(L));
+ double x = lua_tonumber(L, lua_gettop(L));
- printf("forward %d\n", x);
+ printf("forward %f\n", x);
lua_getglobal(L, GLOBAL_POINTER);
LUAScript *lua = (LUAScript*)lua_touserdata(L, lua_gettop(L));
@@ -82,6 +82,33 @@ static int _forward(lua_State *L)
return 0;
}
+static int _coord(lua_State *L)
+{/*
+ Pracro::checkParameters(L,
+ Pracro::T_STRING,
+ Pracro::T_END);
+ */
+ lua_getglobal(L, GLOBAL_POINTER);
+ LUAScript *lua = (LUAScript*)lua_touserdata(L, lua_gettop(L));
+
+ if(!lua) {
+ lua_pushstring(L, "No LUA pointer!");
+ lua_error(L);
+ return 1;
+ }
+
+ if(lua->lua_stop) {
+ printf("stopping...\n");
+ lua_pushstring(L, "stop");
+ lua_error(L);
+ }
+
+ lua_pushnumber(L, lua->out->coordX());
+ lua_pushnumber(L, lua->out->coordY());
+
+ return 2;
+}
+
static int _loadpen(lua_State *L)
{/*
Pracro::checkParameters(L,
@@ -211,9 +238,9 @@ static int _turn(lua_State *L)
Pracro::T_STRING,
Pracro::T_END);
*/
- int x = lua_tonumber(L, lua_gettop(L));
+ double x = lua_tonumber(L, lua_gettop(L));
- printf("turn %d\n", x);
+ printf("turn %f\n", x);
lua_getglobal(L, GLOBAL_POINTER);
LUAScript *lua = (LUAScript*)lua_touserdata(L, lua_gettop(L));
@@ -235,6 +262,22 @@ static int _turn(lua_State *L)
return 0;
}
+static int _playsound(lua_State *L)
+{/*
+ Pracro::checkParameters(L,
+ Pracro::T_STRING,
+ Pracro::T_END);
+ */
+ QString file = lua_tostring(L, lua_gettop(L));
+
+ lua_getglobal(L, GLOBAL_POINTER);
+ LUAScript *lua = (LUAScript*)lua_touserdata(L, lua_gettop(L));
+
+ lua->playSound(file);
+
+ return 0;
+}
+
static int _reset(lua_State *L)
{/*
Pracro::checkParameters(L,
@@ -263,6 +306,36 @@ static int _reset(lua_State *L)
return 0;
}
+void hook(lua_State *L, lua_Debug *ar)
+{
+ lua_getinfo(L, "Snl", ar);
+
+ lua_getglobal(L, GLOBAL_POINTER);
+ LUAScript *lua = (LUAScript*)lua_touserdata(L, lua_gettop(L));
+
+ if(!lua) {
+ lua_pushstring(L, "No LUA pointer!");
+ lua_error(L);
+ return;
+ }
+
+ // printf("kaiman file: %s\n", lua->file.toStdString().c_str());
+
+ if(lua->file == QString(ar->short_src)) {
+ // printf(" ---- currentline: %d\n", ar->currentline);
+ lua->lineChange(ar->currentline);
+ qApp->processEvents();
+ }
+ /*
+ printf("HOOK:\n");
+ printf(" what: %s\n", ar->what);
+ printf(" name: %s\n", ar->name);
+ printf(" source: %s\n", ar->source);
+ printf(" short_src: %s\n", ar->short_src);
+ printf(" currentline: %d\n", ar->currentline);
+ */
+}
+
LUAScript::LUAScript(OutputWindow *o, QString f)
{
DEBUG(luascript, "LUAScript()\n");
@@ -281,6 +354,11 @@ LUAScript::~LUAScript()
DEBUG(luascript, "~LUAScript()\n");
}
+void LUAScript::lineChange(int lineno)
+{
+ emit lineChanged(lineno);
+}
+
void LUAScript::init()
throw(Exception)
{
@@ -298,13 +376,17 @@ void LUAScript::init()
lua_setglobal(L, GLOBAL_POINTER); // Assign it to a global lua var.
lua_register(L, "debug", _debug);
- lua_register(L, "fremad", _forward);
- lua_register(L, "drej", _turn);
+ lua_register(L, "forward", _forward);
+ lua_register(L, "turn", _turn);
lua_register(L, "speed", _speed);
lua_register(L, "scale", _scale);
lua_register(L, "reset", _reset);
lua_register(L, "colour", _colour);
lua_register(L, "loadpen", _loadpen);
+ lua_register(L, "coord", _coord);
+ lua_register(L, "playsound", _playsound);
+
+ lua_sethook(L, hook, LUA_MASKLINE, 0);
}
void LUAScript::cleanup()
@@ -329,6 +411,11 @@ void LUAScript::run()
printf("LUA Thread Stopped!\n");
}
+void LUAScript::playSound(QString file)
+{
+ player.playFile(file);
+}
+
void LUAScript::stopScript()
{
lua_stop = true;