Merge pull request #32 from ief015/master

added lua functions to aid with iterations through all particles
This commit is contained in:
ief015 2011-06-25 01:37:32 -07:00
commit a12f0b40d1
2 changed files with 67 additions and 18 deletions

View File

@ -19,6 +19,8 @@ char *luacon_geterror();
void luacon_close();
int process_command_lua(pixel *vid_buf, char *console, char *console_error);
int getPartIndex_curIdx;
//TPT Interface
int luatpt_test(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_input(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

View File

@ -32,6 +32,10 @@ void luacon_open(){
{"unregister_step", &luatpt_unregister_step},
{"input", &luatpt_input},
{"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}
};
@ -467,8 +471,8 @@ int luatpt_get_property(lua_State* l)
int i, y;
char *prop;
prop = luaL_optstring(l, 1, "");
i = abs(luaL_optint(l, 2, 0));
y = abs(luaL_optint(l, 3, -1));
i = luaL_optint(l, 2, 0);
y = luaL_optint(l, 3, -1);
if(y!=-1 && y < YRES && y >= 0 && i < XRES && i >= 0){
i = pmap[y][i]>>8;
if (i >= NPART)
@ -746,4 +750,43 @@ int luatpt_message_box(lua_State* l)
free(text);
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