int w_Thread_set(lua_State *L) { Thread *t = luax_checkthread(L, 1); std::string name = luax_checklstring(L, 2); ThreadVariant *v; size_t len; const char *str; switch(lua_type(L, 3)) { case LUA_TBOOLEAN: v = new ThreadVariant(luax_toboolean(L, 3)); break; case LUA_TNUMBER: v = new ThreadVariant(lua_tonumber(L, 3)); break; case LUA_TSTRING: str = lua_tolstring(L, 3, &len); v = new ThreadVariant(str, len); break; case LUA_TLIGHTUSERDATA: v = new ThreadVariant(lua_touserdata(L, 3)); break; case LUA_TUSERDATA: v = new ThreadVariant(extractudatatype(L, 3), lua_touserdata(L, 3)); break; default: return luaL_error(L, "Expected boolean, number, string or userdata"); } t->set(name, v); t->lock(); v->release(); t->unlock(); return 0; }
int w_Contact_setEnabled(lua_State *L) { Contact *t = luax_checkcontact(L, 1); bool e = luax_toboolean(L, 2); t->setEnabled(e); return 0; }
int w_Body_setFixedRotation(lua_State *L) { Body *t = luax_checkbody(L, 1); bool b = luax_toboolean(L, 2); luax_catchexcept(L, [&](){ t->setFixedRotation(b); }); return 0; }
int w_setFused(lua_State *L) { // no error checking needed, everything, even nothing // can be converted to a boolean instance()->setFused(luax_toboolean(L, 1)); return 0; }
int w_ParticleSystem_setRelativeDirection(lua_State *L) { ParticleSystem *t = luax_checkparticlesystem(L, 1); bool arg1 = (bool)luax_toboolean(L, 2); t->setRelativeDirection(arg1); return 0; }
int w_PrismaticJoint_setLimitsEnabled(lua_State * L) { PrismaticJoint * t = luax_checkprismaticjoint(L, 1); bool arg1 = luax_toboolean(L, 2); t->setLimitsEnabled(arg1); return 0; }
int w_Body_setBullet(lua_State * L) { Body * t = luax_checkbody(L, 1); bool b = luax_toboolean(L, 2); t->setBullet(b); return 0; }
int w_Body_setAllowSleeping(lua_State * L) { Body * t = luax_checkbody(L, 1); bool b = luax_toboolean(L, 2); t->setAllowSleeping(b); return 0; }
int w_Body_setFixedRotation(lua_State * L) { Body * t = luax_checkbody(L, 1); bool b = luax_toboolean(L, 2); t->setFixedRotation(b); return 0; }
int w_World_setSleepingAllowed(lua_State *L) { World *t = luax_checkworld(L, 1); bool b = luax_toboolean(L, 2); t->setSleepingAllowed(b); return 0; }
int w_Fixture_setSensor(lua_State *L) { Fixture *t = luax_checkfixture(L, 1); bool arg1 = luax_toboolean(L, 2); t->setSensor(arg1); return 0; }
int w_checkMode(lua_State * L) { int w = luaL_checkint(L, 1); int h = luaL_checkint(L, 2); bool fs = luax_toboolean(L, 3); luax_pushboolean(L, instance->checkMode(w, h, fs)); return 1; }
int w_setTextInput(lua_State *L) { bool enable = luax_toboolean(L, 1); if (lua_gettop(L) <= 1) instance()->setTextInput(enable); else { double x = luaL_checknumber(L, 2); double y = luaL_checknumber(L, 3); double w = luaL_checknumber(L, 4); double h = luaL_checknumber(L, 5); instance()->setTextInput(enable, x, y, w, h); } return 0; }
static bool to_message(lua_State * L, Event::Message & msg) { const char * str = luaL_checkstring(L, 1); if(!Event::getConstant(str, msg.type)) return false; switch(msg.type) { case Event::TYPE_KEY_PRESSED: if(!Event::getConstant(luaL_checkstring(L, 2), msg.keyboard.k)) return false; msg.keyboard.u = (unsigned short)luaL_optint(L, 3, 0); return true; case Event::TYPE_KEY_RELEASED: if(!Event::getConstant(luaL_checkstring(L, 2), msg.keyboard.k)) return false; return true; case Event::TYPE_MOUSE_PRESSED: case Event::TYPE_MOUSE_RELEASED: if(!Event::getConstant(luaL_checkstring(L, 2), msg.mouse.b)) return false; msg.mouse.x = luaL_checkint(L, 3); msg.mouse.y = luaL_checkint(L, 4); return true; case Event::TYPE_JOYSTICK_PRESSED: case Event::TYPE_JOYSTICK_RELEASED: msg.joystick.index = luaL_checkint(L, 2); msg.joystick.button = luaL_checkint(L, 3); return true; case Event::TYPE_FOCUS: msg.focus.f = luax_toboolean(L, 2); return true; case Event::TYPE_QUIT: return true; default: return false; } return false; }
int _wrap_setVisible(lua_State * L) { bool b = luax_toboolean(L, 1); instance->setVisible(b); return 0; }
bool luax_checkboolean(lua_State *L, int idx) { luaL_checktype(L, idx, LUA_TBOOLEAN); return luax_toboolean(L, idx); }
int w_setKeyRepeat(lua_State *L) { instance()->setKeyRepeat(luax_toboolean(L, 1)); return 0; }
int w_File_lines_i(lua_State *L) { const int bufsize = 1024; char buf[bufsize]; int linesize = 0; bool newline = false; File *file = luax_checktype<File>(L, lua_upvalueindex(1), FILESYSTEM_FILE_ID); // Only accept read mode at this point. if (file->getMode() != File::MODE_READ) return luaL_error(L, "File needs to stay in read mode."); int64 pos = file->tell(); int64 userpos = -1; if (lua_isnoneornil(L, lua_upvalueindex(2)) == 0) { // User may have changed the file position. userpos = pos; pos = (int64) lua_tonumber(L, lua_upvalueindex(2)); if (userpos != pos) file->seek(pos); } while (!newline && !file->isEOF()) { // This 64-bit to 32-bit integer cast should be safe as it never exceeds bufsize. int read = (int) file->read(buf, bufsize); if (read < 0) return luaL_error(L, "Could not read from file."); linesize += read; for (int i = 0; i < read; i++) { if (buf[i] == '\n') { linesize -= read - i; newline = true; break; } } } if (newline || (file->isEOF() && linesize > 0)) { if (linesize < bufsize) { // We have the line in the buffer on the stack. No 'new' and 'read' needed. lua_pushlstring(L, buf, linesize > 0 && buf[linesize - 1] == '\r' ? linesize - 1 : linesize); if (userpos < 0) file->seek(pos + linesize + 1); } else { char *str = 0; try { str = new char[linesize + 1]; } catch(std::bad_alloc &) { // Can't lua_error (longjmp) in exception handlers. } if (!str) return luaL_error(L, "Out of memory."); file->seek(pos); // Read the \n anyway and save us a call to seek. if (file->read(str, linesize + 1) == -1) { delete [] str; return luaL_error(L, "Could not read from file."); } lua_pushlstring(L, str, str[linesize - 1] == '\r' ? linesize - 1 : linesize); delete [] str; } if (userpos >= 0) { // Save new position in upvalue. lua_pushnumber(L, (lua_Number)(pos + linesize + 1)); lua_replace(L, lua_upvalueindex(2)); file->seek(userpos); } return 1; } // EOF reached. if (userpos >= 0 && luax_toboolean(L, lua_upvalueindex(3))) file->seek(userpos); else file->close(); return 0; }
int w_Quad_flip(lua_State *L) { Quad * quad = luax_checktype<Quad>(L, 1, "Quad", GRAPHICS_QUAD_T); quad->flip(luax_toboolean(L, 2), luax_toboolean(L, 3)); return 0; }
int w_setSymlinksEnabled(lua_State *L) { instance()->setSymlinksEnabled(luax_toboolean(L, 1)); return 0; }
int _wrap_setGrap(lua_State * L) { bool b = luax_toboolean(L, 1); instance->setGrab(b); return 0; }
Variant *Variant::fromLua(lua_State *L, int n, bool allowTables) { Variant *v = NULL; size_t len; const char *str; if (n < 0) // Fix the stack position, we might modify it later n += lua_gettop(L) + 1; switch (lua_type(L, n)) { case LUA_TBOOLEAN: v = new Variant(luax_toboolean(L, n)); break; case LUA_TNUMBER: v = new Variant(lua_tonumber(L, n)); break; case LUA_TSTRING: str = lua_tolstring(L, n, &len); v = new Variant(str, len); break; case LUA_TLIGHTUSERDATA: v = new Variant(lua_touserdata(L, n)); break; case LUA_TUSERDATA: v = new Variant(extractudatatype(L, n), lua_touserdata(L, n)); break; case LUA_TNIL: v = new Variant(); break; case LUA_TTABLE: if (allowTables) { bool success = true; std::vector<std::pair<Variant*, Variant*> > *table = new std::vector<std::pair<Variant*, Variant*> >(); lua_pushnil(L); while (lua_next(L, n)) { Variant *key = fromLua(L, -2, false); if (!key) { success = false; lua_pop(L, 2); break; } Variant *value = fromLua(L, -1, false); if (!value) { delete key; success = false; lua_pop(L, 2); break; } table->push_back(std::make_pair(key, value)); lua_pop(L, 1); } if (success) v = new Variant(table); else delete_table(table); } break; } return v; }
int w_Mesh_setVertexColors(lua_State *L) { Mesh *t = luax_checkmesh(L, 1); t->setVertexColors(luax_toboolean(L, 2)); return 0; }
int w_RevoluteJoint_setMotorEnabled(lua_State *L) { RevoluteJoint *t = luax_checkrevolutejoint(L, 1); bool arg1 = luax_toboolean(L, 2); t->setMotorEnabled(arg1); return 0; }
int w_RevoluteJoint_enableLimit(lua_State *L) { RevoluteJoint *t = luax_checkrevolutejoint(L, 1); bool arg1 = luax_toboolean(L, 2); t->enableLimit(arg1); return 0; }