From f4b015398462fff1a64d70b632390b4f06fe3bbe Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 23 Dec 2012 14:51:13 +0100 Subject: LoadPen, setSpeed, setScale and a bunch of cleanups... --- src/luascript.cc | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) (limited to 'src/luascript.cc') diff --git a/src/luascript.cc b/src/luascript.cc index fb6a7db..df607de 100644 --- a/src/luascript.cc +++ b/src/luascript.cc @@ -82,6 +82,129 @@ static int _forward(lua_State *L) return 0; } +static int _loadpen(lua_State *L) +{/* + Pracro::checkParameters(L, + Pracro::T_STRING, + Pracro::T_END); + */ + const char *pen = lua_tostring(L, lua_gettop(L)); + + printf("load pen %s\n", pen); + + 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->out->loadPen(pen); + + return 0; +} + +static int _speed(lua_State *L) +{/* + Pracro::checkParameters(L, + Pracro::T_STRING, + Pracro::T_END); + */ + int x = lua_tonumber(L, lua_gettop(L)); + + printf("speed %d\n", x); + + 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->out->setSpeed(x); + + return 0; +} + +static int _scale(lua_State *L) +{/* + Pracro::checkParameters(L, + Pracro::T_STRING, + Pracro::T_END); + */ + double x = lua_tonumber(L, lua_gettop(L)); + + printf("scale %f\n", x); + + 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->out->setScale(x); + + return 0; +} + +static int _colour(lua_State *L) +{/* + Pracro::checkParameters(L, + Pracro::T_STRING, + Pracro::T_END); + */ + int r = luaL_checknumber(L, 1); + int g = luaL_checknumber(L, 2); + int b = luaL_checknumber(L, 3); + int a = luaL_checknumber(L, 4); + + printf("colour %d %d %d %d\n", r,b,g,a); + + 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->out->setColour(r,g,b,a); + + return 0; +} + static int _turn(lua_State *L) {/* Pracro::checkParameters(L, @@ -177,7 +300,11 @@ void LUAScript::init() lua_register(L, "debug", _debug); lua_register(L, "fremad", _forward); lua_register(L, "drej", _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); } void LUAScript::cleanup() -- cgit v1.2.3