static int lreset(lua_State *L) { luaL_checktype(L,1,LUA_TUSERDATA); struct particle_system *ps = (struct particle_system *)lua_touserdata(L, 1); particle_system_reset(ps); if (!lua_isnoneornil(L, 2)) { if (!_init_from_table(ps->config, L)) luaL_error(L, "reset particle error"); } return 1; }
static struct particle_system *_new(struct lua_State *L) { int maxParticles = dict_int(L, "maxParticles"); int totalsize = sizeof(struct particle_system) + maxParticles * (sizeof(struct particle) + sizeof(struct matrix)) + sizeof(struct particle_config); struct particle_system * ps = (struct particle_system *)lua_newuserdata(L, totalsize); lua_insert(L, -2); memset(ps, 0, totalsize); init_with_particles(ps, maxParticles); if (!_init_from_table(ps->config, L)) { lua_pop(L, 2); return NULL; } lua_pop(L, 1); return ps; }