added functions to iterate through all particles

+ tpt.start_getPartIndex() --starts the iteration
+ bool tpt.next_getPartIndex() --increases the iteration, returns true if there are more particles to iterate through
+ int tpt.getPartIndex() --get the current iteration value
This commit is contained in:
ief015 2011-06-25 01:32:54 -04:00
parent 87513503ba
commit be79233101
2 changed files with 67 additions and 18 deletions

View File

@ -19,6 +19,8 @@ char *luacon_geterror();
void luacon_close(); void luacon_close();
int process_command_lua(pixel *vid_buf, char *console, char *console_error); int process_command_lua(pixel *vid_buf, char *console, char *console_error);
int getPartIndex_curIdx;
//TPT Interface //TPT Interface
int luatpt_test(lua_State* l); int luatpt_test(lua_State* l);
int luatpt_drawtext(lua_State* l); int luatpt_drawtext(lua_State* l);
@ -45,4 +47,8 @@ int luatpt_register_step(lua_State* l);
int luatpt_unregister_step(lua_State* l); int luatpt_unregister_step(lua_State* l);
int luatpt_input(lua_State* l); int luatpt_input(lua_State* l);
int luatpt_message_box(lua_State* l); int luatpt_message_box(lua_State* l);
int luatpt_get_numOfParts(lua_State* l);
int luatpt_start_getPartIndex(lua_State* l);
int luatpt_getPartIndex(lua_State* l);
int luatpt_next_getPartIndex(lua_State* l);
#endif #endif

View File

@ -32,6 +32,10 @@ void luacon_open(){
{"unregister_step", &luatpt_unregister_step}, {"unregister_step", &luatpt_unregister_step},
{"input", &luatpt_input}, {"input", &luatpt_input},
{"message_box", &luatpt_message_box}, {"message_box", &luatpt_message_box},
{"get_numOfParts", &luatpt_get_numOfParts},
{"start_getPartIndex", &luatpt_start_getPartIndex},
{"next_getPartIndex", &luatpt_next_getPartIndex},
{"getPartIndex", &luatpt_getPartIndex},
{NULL,NULL} {NULL,NULL}
}; };
@ -467,8 +471,8 @@ int luatpt_get_property(lua_State* l)
int i, y; int i, y;
char *prop; char *prop;
prop = luaL_optstring(l, 1, ""); prop = luaL_optstring(l, 1, "");
i = abs(luaL_optint(l, 2, 0)); i = luaL_optint(l, 2, 0);
y = abs(luaL_optint(l, 3, -1)); y = luaL_optint(l, 3, -1);
if(y!=-1 && y < YRES && y >= 0 && i < XRES && i >= 0){ if(y!=-1 && y < YRES && y >= 0 && i < XRES && i >= 0){
i = pmap[y][i]>>8; i = pmap[y][i]>>8;
if (i >= NPART) if (i >= NPART)
@ -746,4 +750,43 @@ int luatpt_message_box(lua_State* l)
free(text); free(text);
return luaL_error(l, "Screen buffer does not exist");; return luaL_error(l, "Screen buffer does not exist");;
} }
int luatpt_get_numOfParts(lua_State* l)
{
lua_pushinteger(l, NUM_PARTS);
return 1;
}
int luatpt_start_getPartIndex(lua_State* l)
{
getPartIndex_curIdx = -1;
return 1;
}
int luatpt_next_getPartIndex(lua_State* l)
{
while(1)
{
getPartIndex_curIdx++;
if(getPartIndex_curIdx >= NPART)
{
getPartIndex_curIdx = 0;
lua_pushboolean(l, 0);
return 1;
}
if(parts[getPartIndex_curIdx].type)
break;
}
lua_pushboolean(l, 1);
return 1;
}
int luatpt_getPartIndex(lua_State* l)
{
if(getPartIndex_curIdx < 0)
{
lua_pushinteger(l, 0);
return 1;
}
lua_pushinteger(l, getPartIndex_curIdx);
return 1;
}
#endif #endif