static int w__typeOf(lua_State *L) { Proxy *p = (Proxy *)lua_touserdata(L, 1); Type *t = luax_type(L, 2); if (!t) luax_pushboolean(L, false); else luax_pushboolean(L, p->type->isa(*t)); return 1; }
int w_File_seek(lua_State *L) { File *file = luax_checkfile(L, 1); lua_Number pos = luaL_checknumber(L, 2); // Push false on negative and precision-problematic numbers. // Better fail than seek to an unknown position. if (pos < 0.0 || pos >= 9007199254740992.0) luax_pushboolean(L, false); else luax_pushboolean(L, file->seek((uint64)pos)); return 1; }
int w_push(lua_State * L) { static Event::Message m; if(!to_message(L, m)) { luax_pushboolean(L, false); return 1; } luax_pushboolean(L, instance->push(m)); return 1; }
static int w__eq(lua_State *L) { Proxy *p1 = (Proxy *)lua_touserdata(L, 1); Proxy *p2 = (Proxy *)lua_touserdata(L, 2); luax_pushboolean(L, p1->object == p2->object && p1->object != nullptr); return 1; }
static int w__eq(lua_State *L) { Proxy *p1 = (Proxy *)lua_touserdata(L, 1); Proxy *p2 = (Proxy *)lua_touserdata(L, 2); luax_pushboolean(L, p1->data == p2->data); return 1; }
static int w__typeOf(lua_State *L) { Proxy *p = (Proxy *)lua_touserdata(L, 1); Type t = luax_type(L, 2); luax_pushboolean(L, p->flags[t]); return 1; }
static int w__release(lua_State *L) { Proxy *p = (Proxy *) lua_touserdata(L, 1); Object *object = p->object; if (object != nullptr) { p->object = nullptr; object->release(); // Fetch the registry table of instantiated objects. luax_getregistry(L, REGISTRY_OBJECTS); if (lua_istable(L, -1)) { // loveobjects[object] = nil lua_pushlightuserdata(L, object); lua_pushnil(L); lua_settable(L, -3); } lua_pop(L, 1); } luax_pushboolean(L, object != nullptr); return 1; }
int w_unmount(lua_State *L) { const char *archive = luaL_checkstring(L, 1); luax_pushboolean(L, instance()->unmount(archive)); return 1; }
int w_isDown(lua_State * L) { int index = luaL_checkint(L, 1); int button = luaL_checkint(L, 2); luax_pushboolean(L, instance->isDown(index, button)); return 1; }
int w_Body_getFixedRotation(lua_State * L) { Body * t = luax_checkbody(L, 1); bool b = t->getFixedRotation(); luax_pushboolean(L, b); return 1; }
int w_Fixture_testPoint(lua_State *L) { Fixture *t = luax_checkfixture(L, 1); float x = (float)luaL_checknumber(L, 2); float y = (float)luaL_checknumber(L, 3); luax_pushboolean(L, t->testPoint(x, y)); return 1; }
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_isCompressed(lua_State *L) { love::filesystem::FileData *data = love::filesystem::luax_getfiledata(L, 1); bool compressed = instance()->isCompressed(data); data->release(); luax_pushboolean(L, compressed); return 1; }
int w_mount(lua_State *L) { const char *archive = luaL_checkstring(L, 1); const char *mountpoint = luaL_checkstring(L, 2); bool append = luax_optboolean(L, 3, false); luax_pushboolean(L, instance()->mount(archive, mountpoint, append)); return 1; }
int w_setMode(lua_State * L) { int w = luaL_checkint(L, 1); int h = luaL_checkint(L, 2); bool fs = luax_optboolean(L, 3, false); bool vsync = luax_optboolean(L, 4, true); int fsaa = luaL_optint(L, 5, 0); luax_pushboolean(L, instance->setMode(w, h, fs, vsync, fsaa)); return 1; }
int w_Joystick_isDown(lua_State *L) { Joystick *j = luax_checkjoystick(L, 1); luaL_checkinteger(L, 2); std::vector<int> buttons; for (int i = 2; i <= lua_gettop(L); i++) buttons.push_back(luaL_checkint(L, i) - 1); luax_pushboolean(L, j->isDown(buttons)); return 1; }
int w_File_flush(lua_State *L) { File *file = luax_checkfile(L, 1); bool success = false; try { success = file->flush(); } catch (love::Exception &e) { return luax_ioError(L, "%s", e.what()); } luax_pushboolean(L, success); return 1; }
int w_isDown(lua_State *L) { Keyboard::Key k; int num = lua_gettop(L); std::vector<Keyboard::Key> keylist; keylist.reserve(num); for (int i = 0; i < num; i++) { if (Keyboard::getConstant(luaL_checkstring(L, i+1), k)) keylist.push_back(k); } luax_pushboolean(L, instance()->isDown(keylist)); return 1; }
int w_isScancodeDown(lua_State *L) { Keyboard::Scancode scancode; int num = lua_gettop(L); std::vector<Keyboard::Scancode> scancodelist; scancodelist.reserve(num); for (int i = 0; i < num; i++) { if (Keyboard::getConstant(luaL_checkstring(L, i+1), scancode)) scancodelist.push_back(scancode); } luax_pushboolean(L, instance()->isScancodeDown(scancodelist)); return 1; }
int w_isDown(lua_State * L) { int index = luaL_checkint(L, 1)-1; unsigned int num = lua_gettop(L); int * buttonlist = new int[num]; unsigned int counter = 0; for (unsigned int i = 1; i < num; i++) { buttonlist[counter++] = (int) luaL_checknumber(L, i+1)-1; } buttonlist[counter] = -1; luax_pushboolean(L, instance->isDown(index, buttonlist)); delete[] buttonlist; return 1; }
int w_isDown(lua_State *L) { Keyboard::Key k; unsigned int num = lua_gettop(L); Keyboard::Key *keylist = new Keyboard::Key[num+1]; unsigned int counter = 0; for (unsigned int i = 0; i < num; i++) { if (Keyboard::getConstant(luaL_checkstring(L, i+1), k)) keylist[counter++] = k; } keylist[counter] = Keyboard::KEY_MAX_ENUM; luax_pushboolean(L, instance->isDown(keylist)); delete[] keylist; return 1; }
int w_File_write(lua_State *L) { File *file = luax_checkfile(L, 1); bool result = false; if (lua_isstring(L, 2)) { try { size_t datasize = 0; const char *data = lua_tolstring(L, 2, &datasize); if (!lua_isnoneornil(L, 3)) datasize = luaL_checkinteger(L, 3); result = file->write(data, datasize); } catch (love::Exception &e) { return luax_ioError(L, "%s", e.what()); } } else if (luax_istype(L, 2, DATA_ID)) { try { love::Data *data = luax_totype<love::Data>(L, 2, DATA_ID); result = file->write(data, luaL_optinteger(L, 3, data->getSize())); } catch (love::Exception &e) { return luax_ioError(L, "%s", e.what()); } } else { return luaL_argerror(L, 2, "string or data expected"); } luax_pushboolean(L, result); return 1; }
int w_isCompressed(lua_State *L) { // Convert to FileData, if necessary. if (lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_T)) luax_convobj(L, 1, "filesystem", "newFileData"); love::filesystem::FileData *data = luax_checktype<love::filesystem::FileData>(L, 1, "FileData", FILESYSTEM_FILE_DATA_T); bool compressed = false; try { compressed = instance->isCompressed(data); } catch (love::Exception &e) { return luaL_error(L, "%s", e.what()); } luax_pushboolean(L, compressed); return 1; }
int w_Joystick_setVibration(lua_State *L) { Joystick *j = luax_checkjoystick(L, 1); bool success = false; if (lua_isnoneornil(L, 2)) { // Disable joystick vibration if no argument is given. success = j->setVibration(); } else { float left = (float) luaL_checknumber(L, 2); float right = (float) luaL_optnumber(L, 3, left); success = j->setVibration(left, right); } luax_pushboolean(L, success); return 1; }
int w_Thread_start(lua_State *L) { LuaThread *t = luax_checkthread(L, 1); std::vector<Variant> args; int nargs = lua_gettop(L) - 1; for (int i = 0; i < nargs; ++i) { args.push_back(Variant::fromLua(L, i+2)); if (args.back().getType() == Variant::UNKNOWN) { args.clear(); return luaL_argerror(L, i+2, "boolean, number, string, love type, or flat table expected"); } } luax_pushboolean(L, t->start(args)); return 1; }
int w_File_open(lua_State *L) { File *file = luax_checkfile(L, 1); const char *str = luaL_checkstring(L, 2); File::Mode mode; if (!File::getConstant(str, mode)) return luaL_error(L, "Incorrect file open mode: %s", str); try { luax_pushboolean(L, file->open(mode)); } catch (love::Exception &e) { return luax_ioError(L, "%s", e.what()); } return 1; }
int w_File_lines(lua_State *L) { File *file = luax_checkfile(L, 1); lua_pushnumber(L, 0); // File position. luax_pushboolean(L, file->getMode() != File::MODE_CLOSED); // Save current file mode. if (file->getMode() != File::MODE_READ) { if (file->getMode() != File::MODE_CLOSED) file->close(); bool success = false; luax_catchexcept(L, [&](){ success = file->open(File::MODE_READ); }); if (!success) return luaL_error(L, "Could not open file."); } lua_pushcclosure(L, w_File_lines_i, 3); return 1; }
int w_Font_hasGlyphs(lua_State *L) { Font *t = luax_checkfont(L, 1); bool hasglyph = false; int count = std::max(lua_gettop(L) - 1, 1); luax_catchexcept(L, [&]() { for (int i = 2; i < count + 2; i++) { if (lua_type(L, i) == LUA_TSTRING) hasglyph = t->hasGlyphs(luax_checkstring(L, i)); else hasglyph = t->hasGlyph((uint32) luaL_checknumber(L, i)); if (!hasglyph) break; } }); luax_pushboolean(L, hasglyph); return 1; }
int w_Joystick_isGamepadDown(lua_State *L) { Joystick *j = luax_checkjoystick(L, 1); std::vector<Joystick::GamepadButton> buttons; buttons.reserve(lua_gettop(L) - 1); luaL_checkstring(L, 2); for (int i = 2; i <= lua_gettop(L); i++) { const char *str = luaL_checkstring(L, i); Joystick::GamepadButton button; if (!joystick::Joystick::getConstant(str, button)) return luaL_error(L, "Invalid gamepad button: %s", str); buttons.push_back(button); } luax_pushboolean(L, j->isGamepadDown(buttons)); return 1; }
int w_File_setBuffer(lua_State *L) { File *file = luax_checkfile(L, 1); const char *str = luaL_checkstring(L, 2); int64 size = (int64) luaL_optnumber(L, 3, 0.0); File::BufferMode bufmode; if (!File::getConstant(str, bufmode)) return luaL_error(L, "Incorrect file buffer mode: %s", str); bool success = false; try { success = file->setBuffer(bufmode, size); } catch (love::Exception &e) { return luax_ioError(L, "%s", e.what()); } luax_pushboolean(L, success); return 1; }