diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2011-05-30 18:44:17 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2011-05-30 18:44:17 (GMT) |
| commit | d5f1a4cfd073f87d636e6975c28d42b8a7456840 (patch) | |
| tree | 96da8a76a924221d1fca5769ce1ef2d24c6a75e7 /src | |
| parent | cad644824d3e1bc5aa1dc72404c2f54cf5342e92 (diff) | |
| download | powder-d5f1a4cfd073f87d636e6975c28d42b8a7456840.zip powder-d5f1a4cfd073f87d636e6975c28d42b8a7456840.tar.gz | |
Many methods for Lua console
Diffstat (limited to 'src')
| -rw-r--r-- | src/luaconsole.c | 288 |
1 files changed, 287 insertions, 1 deletions
diff --git a/src/luaconsole.c b/src/luaconsole.c index 7b8f63a..d019667 100644 --- a/src/luaconsole.c +++ b/src/luaconsole.c @@ -1,4 +1,6 @@ #ifdef LUACONSOLE +#include <powder.h> +#include <console.h> #include <luaconsole.h> lua_State *l; @@ -6,6 +8,23 @@ void luacon_open(){ const static struct luaL_reg tptluaapi [] = { {"test", &luatpt_test}, {"drawtext", &luatpt_drawtext}, + {"create", &luatpt_create}, + {"set_pause", &luatpt_setpause}, + {"toggle_pause", &luatpt_togglepause}, + {"set_console", &luatpt_setconsole}, + {"log", &luatpt_log}, + {"reset_pressure", &luatpt_reset_pressure}, + {"reset_velocity", &luatpt_reset_velocity}, + {"reset_spark", &luatpt_reset_spark}, + {"set_property", &luatpt_set_property}, + {"get_property", &luatpt_get_property}, + {"drawpixel", &luatpt_drawpixel}, + {"drawrect", &luatpt_drawrect}, + {"fillrect", &luatpt_fillrect}, + {"textwidth", &luatpt_textwidth}, + {"get_name", &luatpt_get_name}, + {"set_shortcuts", &luatpt_set_shortcuts}, + {"delete", &luatpt_delete}, {NULL,NULL} }; @@ -62,7 +81,7 @@ int luatpt_test(lua_State* l) int testint = 0; testint = luaL_optint(l, 1, 0); printf("Test successful, got %d\n", testint); - return 1; + return 0; } int luatpt_drawtext(lua_State* l) { @@ -82,4 +101,271 @@ int luatpt_drawtext(lua_State* l) return -1; } +int luatpt_create(lua_State* l) +{ + lua_pushstring(l, "not implemented"); + lua_error(l); + //TODO: Implement luatpt_create (Create a particle) + return -1; +} + +int luatpt_setpause(lua_State* l) +{ + int pausestate; + pausestate = luaL_optint(l, 1, 0); + sys_pause = (pausestate==0?0:1); + return 0; +} + +int luatpt_togglepause(lua_State* l) +{ + sys_pause=!sys_pause; + return 0; +} + +int luatpt_setconsole(lua_State* l) +{ + int consolestate; + consolestate = luaL_optint(l, 1, 0); + console_mode = (consolestate==0?0:1); + return 0; +} + +int luatpt_log(lua_State* l) +{ + char *buffer; + buffer = luaL_optstring(l, 1, ""); + strcpy(console_error, buffer); + return 0; +} + +int luatpt_reset_pressure(lua_State* l) +{ + int nx, ny; + int x1, y1, width, height; + float value; + x1 = abs(luaL_optint(l, 1, 0)); + y1 = abs(luaL_optint(l, 2, 0)); + width = abs(luaL_optint(l, 3, XRES/CELL)); + height = abs(luaL_optint(l, 4, YRES/CELL)); + value = (float)luaL_optint(l, 5, 0.0f); + if(value > 256.0f) + value = 256.0f; + else if(value < -256.0f) + value = -256.0f; + + if(x1 > (XRES/CELL)-1) + x1 = (XRES/CELL)-1; + if(y1 > (YRES/CELL)-1) + y1 = (YRES/CELL)-1; + if(x1+width > (XRES/CELL)-1) + width = (XRES/CELL)-x1; + if(y1+height > (YRES/CELL)-1) + height = (YRES/CELL)-y1; + for (nx = x1; nx<x1+width; nx++) + for (ny = y1; ny<y1+height; ny++) + { + pv[ny][nx] = value; + } + return 0; +} + +int luatpt_reset_velocity(lua_State* l) +{ + int nx, ny; + int x1, y1, width, height; + x1 = abs(luaL_optint(l, 1, 0)); + y1 = abs(luaL_optint(l, 2, 0)); + width = abs(luaL_optint(l, 3, XRES/CELL)); + height = abs(luaL_optint(l, 4, YRES/CELL)); + if(x1 > (XRES/CELL)-1) + x1 = (XRES/CELL)-1; + if(y1 > (YRES/CELL)-1) + y1 = (YRES/CELL)-1; + if(x1+width > (XRES/CELL)-1) + width = (XRES/CELL)-x1; + if(y1+height > (YRES/CELL)-1) + height = (YRES/CELL)-y1; + for (nx = x1; nx<x1+width; nx++) + for (ny = y1; ny<y1+height; ny++) + { + vx[ny][nx] = 0; + vy[ny][nx] = 0; + } + return 0; +} + +int luatpt_reset_spark(lua_State* l) +{ + int i; + for (i=0; i<NPART; i++) + { + if (parts[i].type==PT_SPRK) + { + parts[i].type = parts[i].ctype; + parts[i].life = 4; + } + } + return 0; +} + +int luatpt_set_property(lua_State* l) +{ + lua_pushstring(l, "not implemented"); + lua_error(l); + //TODO: Implement luatpt_set_property + return -1; +} + +int luatpt_get_property(lua_State* l) +{ + int i; + char *prop; + prop = luaL_optstring(l, 1, ""); + i = luaL_optint(l, 2, 0); + if (i < 0 || i >= NPART) + return -1; + if (parts[i].type) + { + if (strcmp(prop,"type")==0){ + lua_pushinteger(l, parts[i].type); + return 1; + } + if (strcmp(prop,"life")==0){ + lua_pushinteger(l, parts[i].life); + return 1; + } + if (strcmp(prop,"ctype")==0){ + lua_pushinteger(l, parts[i].ctype); + return 1; + } + if (strcmp(prop,"temp")==0){ + lua_pushinteger(l, parts[i].temp); + return 1; + } + if (strcmp(prop,"tmp")==0){ + lua_pushinteger(l, parts[i].tmp); + return 1; + } + if (strcmp(prop,"vy")==0){ + lua_pushnumber(l, (double)parts[i].vy); + return 1; + } + if (strcmp(prop,"vx")==0){ + lua_pushnumber(l, (double)parts[i].vx); + return 1; + } + if (strcmp(prop,"x")==0){ + lua_pushinteger(l, parts[i].x); + return 1; + } + if (strcmp(prop,"y")==0){ + lua_pushinteger(l, parts[i].y); + return 1; + } + } + + return -1; +} + +int luatpt_drawpixel(lua_State* l) +{ + int x, y, r, g, b, a; + x = luaL_optint(l, 1, 0); + y = luaL_optint(l, 2, 0); + r = luaL_optint(l, 3, 255); + g = luaL_optint(l, 4, 255); + b = luaL_optint(l, 5, 255); + a = luaL_optint(l, 6, 255); + + if(x > XRES || y > YRES || x < 0 || y < 0) + return -1; + if (vid_buf!=NULL) + { + drawpixel(vid_buf, x, y, r, g, b, a); + return 0; + } + return -1; + +} + +int luatpt_drawrect(lua_State* l) +{ + int x, y, w, h, r, g, b, a; + x = luaL_optint(l, 1, 0); + y = luaL_optint(l, 2, 0); + w = luaL_optint(l, 3, 10); + h = luaL_optint(l, 4, 10); + r = luaL_optint(l, 5, 255); + g = luaL_optint(l, 6, 255); + b = luaL_optint(l, 7, 255); + a = luaL_optint(l, 8, 255); + + if(x > XRES || y > YRES || x < 0 || y < 0) + return -1; + if (vid_buf!=NULL) + { + drawrect(vid_buf, x, y, w, h, r, g, b, a); + return 0; + } + return -1; +} + +int luatpt_fillrect(lua_State* l) +{ + int x,y,w,h,r,g,b,a; + x = luaL_optint(l, 1, 0); + y = luaL_optint(l, 2, 0); + w = luaL_optint(l, 3, 10); + h = luaL_optint(l, 4, 10); + r = luaL_optint(l, 5, 255); + g = luaL_optint(l, 6, 255); + b = luaL_optint(l, 7, 255); + a = luaL_optint(l, 8, 255); + + if(x > XRES || y > YRES || x < 0 || y < 0) + return -1; + if (vid_buf!=NULL) + { + fillrect(vid_buf, x, y, w, h, r, g, b, a); + return 0; + } + return -1; +} + +int luatpt_textwidth(lua_State* l) +{ + char * string; + int strwidth = 0; + string = luaL_optstring(l, 1, ""); + strwidth = textwidth(string); + lua_pushinteger(l, strwidth); + return 1; +} + +int luatpt_get_name(lua_State* l) +{ + if (svf_login){ + lua_pushstring(l, ""); + return 1; + } + lua_pushstring(l, ""); + return 1; +} + +int luatpt_set_shortcuts(lua_State* l) +{ + int state; + state = luaL_optint(l, 1, 0); + sys_shortcuts = (state==0?0:1); + return 0; +} + +int luatpt_delete(lua_State* l) +{ + lua_pushstring(l, "not implemented"); + lua_error(l); + //TODO: Implement luatpt_delete (Delete particle) + return -1; +} #endif |
