├── .gitignore ├── CMakeLists.txt ├── INSTALL.md ├── LICENSE ├── README.md ├── cmake ├── FindLua.cmake ├── FindLuaJIT.cmake ├── FindSDL2.cmake ├── FindSysQueue.cmake └── config.h.in ├── common ├── CMakeLists.txt ├── array.c ├── array.h ├── common.c ├── common.h ├── rwops.c ├── rwops.h ├── surface.c ├── surface.h ├── table.c ├── table.h ├── variant.c ├── variant.h ├── video.c └── video.h ├── examples ├── CMakeLists.txt ├── audio │ ├── audio-processor.lua │ ├── audio.lua │ └── gun.wav ├── font │ ├── DejaVuSans.ttf │ └── font.lua ├── image │ ├── Lua-SDL2.png │ └── image.lua ├── joystick │ └── joystick.lua ├── keyboard │ └── keyboard.lua ├── paths │ └── paths.lua ├── rwops │ └── rwops.lua ├── tcp │ ├── client.lua │ └── server.lua ├── threads │ └── channel.lua └── udp │ ├── client.lua │ └── server.lua ├── extern └── queue │ └── sys │ └── queue.h ├── lua-sdl2-scm-3.rockspec ├── rocks └── config.h ├── sdl-image ├── CMakeLists.txt └── src │ └── image.c ├── sdl-mixer ├── CMakeLists.txt └── src │ └── mixer.c ├── sdl-net ├── CMakeLists.txt └── src │ └── net.c ├── sdl-ttf ├── CMakeLists.txt └── src │ └── ttf.c ├── src ├── SDL.c ├── audio.c ├── audio.h ├── channel.c ├── channel.h ├── clipboard.c ├── clipboard.h ├── cpu.c ├── cpu.h ├── display.c ├── display.h ├── events.c ├── events.h ├── filesystem.c ├── filesystem.h ├── gamecontroller.c ├── gamecontroller.h ├── gl.c ├── gl.h ├── haptic.c ├── haptic.h ├── joystick.c ├── joystick.h ├── keyboard.c ├── keyboard.h ├── logging.c ├── logging.h ├── mouse.c ├── mouse.h ├── platform.c ├── platform.h ├── power.c ├── power.h ├── rectangle.c ├── rectangle.h ├── renderer.c ├── renderer.h ├── texture.c ├── texture.h ├── thread.c ├── thread.h ├── timer.c ├── timer.h ├── vulkan.c ├── vulkan.h ├── window.c └── window.h ├── tutorials ├── 01-initialization │ └── tutorial.lua ├── 02-window │ └── tutorial.lua ├── 03-events │ └── tutorial.lua ├── 04-drawing │ ├── Lua-SDL2.png │ └── tutorial.lua ├── 05-sound │ ├── gun.wav │ └── tutorial.lua ├── 06-text │ ├── DejaVuSans.ttf │ └── tutorial.lua ├── 07-bouncing │ ├── Lua-SDL2.png │ └── tutorial.lua └── CMakeLists.txt └── windows ├── 32 ├── SDL2.dll ├── SDL2_image.dll ├── SDL2_mixer.dll ├── SDL2_net.dll ├── SDL2_ttf.dll ├── libFLAC-8.dll ├── libfreetype-6.dll ├── libjpeg-9.dll ├── libmikmod-2.dll ├── libmodplug-1.dll ├── libogg-0.dll ├── libpng16-16.dll ├── libtiff-5.dll ├── libvorbis-0.dll ├── libvorbisfile-3.dll ├── libwebp-4.dll ├── lua.dll ├── smpeg2.dll └── zlib1.dll ├── 64 ├── SDL2.dll ├── SDL2_image.dll ├── SDL2_mixer.dll ├── SDL2_net.dll ├── SDL2_ttf.dll ├── libFLAC-8.dll ├── libfreetype-6.dll ├── libjpeg-9.dll ├── libmikmod-2.dll ├── libmodplug-1.dll ├── libogg-0.dll ├── libpng16-16.dll ├── libtiff-5.dll ├── libvorbis-0.dll ├── libvorbisfile-3.dll ├── libwebp-4.dll ├── lua.dll ├── smpeg2.dll └── zlib1.dll ├── CMakeLists.txt ├── mingw-32 ├── SDL2.dll ├── SDL2_image.dll ├── SDL2_mixer.dll ├── SDL2_net.dll ├── SDL2_ttf.dll ├── libFLAC-8.dll ├── libfreetype-6.dll ├── libjpeg-9.dll ├── libmodplug-1.dll ├── libogg-0.dll ├── libpng16-16.dll ├── libtiff-5.dll ├── libvorbis-0.dll ├── libvorbisfile-3.dll ├── libwebp-4.dll ├── lua.dll ├── smpeg2.dll └── zlib1.dll └── mingw-64 ├── SDL2.dll ├── SDL2_image.dll ├── SDL2_mixer.dll ├── SDL2_net.dll ├── SDL2_ttf.dll ├── libFLAC-8.dll ├── libfreetype-6.dll ├── libjpeg-9.dll ├── libmikmod-2.dll ├── libmodplug-1.dll ├── libogg-0.dll ├── libpng16-16.dll ├── libtiff-5.dll ├── libvorbis-0.dll ├── libvorbisfile-3.dll ├── libwebp-4.dll ├── lua.dll ├── smpeg2.dll └── zlib1.dll /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | *.o 3 | *.so 4 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # CMakeLists.txt -- build system for LuaSDL2 3 | # 4 | # Copyright (c) 2013, 2014 David Demelier 5 | # Copyright (c) 2014, 2015 Joseph Wallace 6 | # Copyright (c) 2017 Webster Sheets 7 | # 8 | # Permission to use, copy, modify, and/or distribute this software for any 9 | # purpose with or without fee is hereby granted, provided that the above 10 | # copyright notice and this permission notice appear in all copies. 11 | # 12 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 13 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 14 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 15 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 16 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 18 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19 | # 20 | 21 | cmake_minimum_required(VERSION 3.10) 22 | project(Lua-SDL2 C) 23 | 24 | set(CMAKE_MODULE_PATH "${Lua-SDL2_SOURCE_DIR}/cmake") 25 | 26 | include(CheckStructHasMember) 27 | include(GNUInstallDirs) 28 | 29 | # Project information. Follows the [SEMVER](semver.org) standard 30 | set(BINDING_MAJOR "2") 31 | set(BINDING_MINOR "1") 32 | 33 | # Latest implemented SDL2 version. Only increment when a new SDL2 version is 34 | # completely implemented. 35 | set(MAJOR "2") 36 | set(MINOR "0") 37 | set(PATCH "5") 38 | set(VERSION "${BINDING_MAJOR}.${BINDING_MINOR} for SDL ${MAJOR}.${MINOR}.${PATCH}") 39 | 40 | set(WITH_DOCSDIR "share/docs/Lua-SDL2" 41 | CACHE STRING "Path to install examples") 42 | set(WITH_LUAVER "5.3" 43 | CACHE STRING "Version of Lua to use: 5.4 (default), 5.3, 5.2, 5.1 or JIT)") 44 | 45 | find_package(SDL2 REQUIRED) 46 | find_package(SDL2 COMPONENTS image mixer net ttf) 47 | 48 | if (WITH_LUAVER MATCHES "JIT") 49 | find_package(LuaJIT REQUIRED) 50 | # LuaJIT is 5.1 for the moment. 51 | set(Lua_VERSION "5.1") 52 | else () 53 | find_package(Lua ${WITH_LUAVER} EXACT REQUIRED) 54 | endif () 55 | 56 | # Check for SDL_DropEvent.windowID (See GH-#61) 57 | set(CMAKE_REQUIRED_INCLUDES ${SDL2_INCLUDE_DIR}) 58 | set(CMAKE_REQUIRED_DEFINITIONS -DSDL_MAIN_HANDLED) 59 | check_struct_has_member(SDL_DropEvent windowID SDL.h HAVE_DROPEVENT_WINDOW_ID) 60 | 61 | set( 62 | SOURCES 63 | src/audio.c 64 | src/audio.h 65 | src/channel.c 66 | src/channel.h 67 | src/clipboard.c 68 | src/clipboard.h 69 | src/cpu.c 70 | src/cpu.h 71 | src/display.c 72 | src/display.h 73 | src/events.c 74 | src/events.h 75 | src/filesystem.c 76 | src/filesystem.h 77 | src/gamecontroller.c 78 | src/gamecontroller.h 79 | src/gl.c 80 | src/gl.h 81 | src/haptic.c 82 | src/haptic.h 83 | src/joystick.c 84 | src/joystick.h 85 | src/keyboard.c 86 | src/keyboard.h 87 | src/logging.c 88 | src/logging.h 89 | src/mouse.c 90 | src/mouse.h 91 | src/platform.c 92 | src/platform.h 93 | src/power.c 94 | src/power.h 95 | src/rectangle.c 96 | src/rectangle.h 97 | src/renderer.c 98 | src/renderer.h 99 | src/SDL.c 100 | src/texture.c 101 | src/texture.h 102 | src/thread.c 103 | src/thread.h 104 | src/timer.c 105 | src/timer.h 106 | src/vulkan.c 107 | src/vulkan.h 108 | src/window.c 109 | src/window.h 110 | ) 111 | 112 | configure_file( 113 | ${Lua-SDL2_SOURCE_DIR}/cmake/config.h.in 114 | ${Lua-SDL2_BINARY_DIR}/config.h 115 | ) 116 | 117 | include_directories(${Lua-SDL2_BINARY_DIR}) 118 | 119 | if (WIN32) 120 | add_definitions("/D_CRT_SECURE_NO_WARNINGS") 121 | else () 122 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra") 123 | endif () 124 | 125 | # We always use _FOREACH_SAFE. 126 | find_package(SysQueue) 127 | if (NOT SYSQUEUE_FOUND 128 | OR NOT SYSQUEUE_SLIST_FOREACH_SAFE 129 | OR NOT SYSQUEUE_STAILQ_FOREACH_SAFE 130 | OR NOT SYSQUEUE_LIST_FOREACH_SAFE 131 | OR NOT SYSQUEUE_TAILQ_FOREACH_SAFE) 132 | include_directories(BEFORE ${Lua-SDL2_SOURCE_DIR}/extern/queue) 133 | endif () 134 | 135 | # Common code for modules 136 | add_subdirectory(common) 137 | 138 | add_library( 139 | SDL 140 | MODULE 141 | ${SOURCES} 142 | ) 143 | 144 | if (APPLE) 145 | # 146 | # TODO: change once there is a better CMake variant for this issue. 147 | # 148 | # Lua modules must not link to Lua, unfortunately add_library(MODULE) uses 149 | # -bundle on macOS while it should use -dynamiclib instead. 150 | # 151 | set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-dynamiclib -undefined dynamic_lookup") 152 | endif () 153 | 154 | set_target_properties(SDL PROPERTIES PREFIX "") 155 | target_link_libraries(SDL common) 156 | 157 | install( 158 | TARGETS SDL 159 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/lua/${Lua_VERSION} 160 | ) 161 | 162 | # Other libSDL sub modules 163 | option(WITH_IMAGE "Enable SDL_image" On) 164 | option(WITH_MIXER "Enable SDL_mixer" On) 165 | option(WITH_TTF "Enable SDL_ttf" On) 166 | option(WITH_NET "Enable SDL_net" On) 167 | 168 | if (WITH_IMAGE AND TARGET SDL2::image) 169 | add_subdirectory(sdl-image) 170 | endif () 171 | 172 | if (WITH_MIXER AND TARGET SDL2::mixer) 173 | add_subdirectory(sdl-mixer) 174 | endif () 175 | 176 | if (WITH_TTF AND TARGET SDL2::ttf) 177 | add_subdirectory(sdl-ttf) 178 | endif () 179 | 180 | if (WITH_NET AND TARGET SDL2::net) 181 | add_subdirectory(sdl-net) 182 | endif () 183 | 184 | # For the examples and tutorials 185 | add_subdirectory(examples) 186 | add_subdirectory(tutorials) 187 | 188 | # For Windows DLL 189 | if (WIN32) 190 | add_subdirectory(windows) 191 | endif () 192 | 193 | # CPack configuration 194 | if (WIN32) 195 | set(CPACK_PACKAGE_NAME "Lua-SDL2") 196 | set(CPACK_NSIS_PACKAGE_NAME "Lua-SDL2") 197 | 198 | # This determine the *target* architecture 199 | if (CMAKE_SIZEOF_VOID_P MATCHES "8") 200 | set(WINARCH "amd64") 201 | else () 202 | set(WINARCH "x86") 203 | endif () 204 | 205 | if (MINGW) 206 | set(GENERATOR "MinGW") 207 | else () 208 | set(GENERATOR "VC") 209 | endif () 210 | 211 | set(CPACK_GENERATOR "ZIP") 212 | set(CPACK_MONOLITHIC_INSTALL FALSE) 213 | 214 | set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE") 215 | set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README") 216 | 217 | set(CPACK_PACKAGE_VENDOR "Malikania") 218 | set(CPACK_PACKAGE_VERSION "${VERSION}") 219 | set(CPACK_PACKAGE_VERSION_MAJOR ${MAJOR}) 220 | set(CPACK_PACKAGE_VERSION_MINOR ${MINOR}) 221 | set(CPACK_PACKAGE_FILE_NAME "Lua-SDL2-${VERSION}-${GENERATOR}-${WINARCH}") 222 | set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README") 223 | set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Lua-SDL2") 224 | else () 225 | set(CPACK_GENERATOR "TGZ") 226 | endif () 227 | 228 | set(CPACK_SOURCE_PACKAGE_FILE_NAME "Lua-SDL2-${VERSION}-source") 229 | set(CPACK_SOURCE_GENERATOR "ZIP;TGZ") 230 | set(CPACK_SOURCE_IGNORE_FILES ".hg;_build_;.git") 231 | 232 | include(CPack) 233 | -------------------------------------------------------------------------------- /INSTALL.md: -------------------------------------------------------------------------------- 1 | Lua-SDL2 INSTALL 2 | ================ 3 | 4 | Lua-SDL2 installation guide. 5 | 6 | Requirements 7 | ============ 8 | 9 | * [Lua](http://lua.org), mandatory (Lua 5.1, LuaJIT, Lua 5.2, or Lua 5.3) 10 | * [SDL 2.0.1+](http://libsdl.org), mandatory 11 | * Either [CMake](http://cmake.org) or [LuaRocks](https://luarocks.org), for building only 12 | 13 | And optional libraries for the official SDL modules: 14 | 15 | * [SDL_mixer](http://www.libsdl.org/projects/SDL_mixer) 16 | * [SDL_ttf](http://www.libsdl.org/projects/SDL_ttf) 17 | * [SDL_net](http://www.libsdl.org/projects/SDL_net) 18 | * [SDL_image](http://www.libsdl.org/projects/SDL_image) 19 | 20 | Installation (LuaRocks) 21 | ======================= 22 | 23 | $ luarocks install lua-sdl2 24 | 25 | Will install Lua-SDL2 from the Luarocks repositories. 26 | 27 | If you want to install a development version, clone the repository and run: 28 | 29 | $ luarocks install lua-sdl2-scm-3.rockspec 30 | 31 | Currently, there is no way to disable the mixer/ttf/net/image modules. 32 | Eventually they will be split into separate rockspecs. 33 | 34 | Manually locating SDL2 headers 35 | ------------------------------ 36 | 37 | By default, Luarocks expects to find the SDL2 headers under `/usr/include/SDL2/`. 38 | You can customize the prefix by setting the SDL2_INCDIR variable in your Luarocks 39 | configuration or on the command line for installing. 40 | 41 | On most systems, you need to specify the path *containing* the `SDL2/` folder, 42 | for example `/usr/local/include`. 43 | 44 | On Windows, you need to specify the folder containing the headers directly, 45 | such as `c:\include\SDL2\`. 46 | 47 | Installation (CMake) 48 | ==================== 49 | 50 | Take care to substitute version with the current Lua-SDL2 version. 51 | 52 | $ tar xvzf Lua-SDL2-version.tar.gz 53 | $ cd Lua-SDL2-version 54 | $ mkdir _build_ 55 | $ cd _build_ 56 | $ cmake .. 57 | $ make 58 | # make install 59 | 60 | Customizing the build (CMake) 61 | ============================= 62 | 63 | Several options are available. The following commands are expected to be ran in 64 | the _build_ directory created above. 65 | 66 | Disable SDL_mixer 67 | ----------------- 68 | 69 | $ cmake .. -DWITH_MIXER=Off 70 | 71 | Disable SDL_ttf 72 | --------------- 73 | 74 | $ cmake .. -DWITH_TTF=Off 75 | 76 | Disable SDL_net 77 | --------------- 78 | 79 | $ cmake .. -DWITH_NET=Off 80 | 81 | Disable SDL_image 82 | ----------------- 83 | 84 | $ cmake .. -DWITH_IMAGE=Off 85 | 86 | Disable installation of examples 87 | -------------------------------- 88 | 89 | $ cmake .. -DWITH_DOCS=Off 90 | 91 | Change the installation path of libraries 92 | ----------------------------------------- 93 | 94 | $ cmake .. -DLUA_LIBDIR=/path/to/install/libraries 95 | 96 | Note that this is relative to CMAKE_INSTALL_PREFIX. 97 | 98 | Change the installation directory of examples 99 | --------------------------------------------- 100 | 101 | $ cmake .. -DWITH_DOCSDIR=/path/to/install/examples 102 | 103 | Note that this is relative to CMAKE_INSTALL_PREFIX. 104 | 105 | Changing the Lua version 106 | ------------------------ 107 | 108 | You can change the Lua version by setting the WITH_LUAVER CMake variable; 109 | supported values are: 110 | 111 | * 53, Lua 5.3 112 | * 52, Lua 5.2 (default) 113 | * 51, Lua 5.1 114 | * JIT, LuaJIT 115 | 116 | $ cmake .. -DWITH_LUAVER=JIT 117 | 118 | Changing the Lua location 119 | ------------------------- 120 | 121 | It is sometimes useful to explicitly specify the path to the selected Lua version's include and library directories. The variables to set depend on the configured version:

122 | 123 | $ cmake .. -DWITH_LUAVER=53 -DLUA53_INCLUDE_DIR=/path/to/headers/ 124 | 125 | $ cmake .. -DWITH_LUAVER=52 -DLUA52_INCLUDE_DIR=/path/to/headers/ 126 | 127 | $ cmake .. -DWITH_LUAVER=51 -DLUA_INCLUDE_DIR=/path/to/headers/ 128 | 129 | $ cmake .. -DWITH_LUAVER=JIT -DLUAJIT_INCLUDE_DIR=/path/to/headers/ 130 | 131 | Also note that the include directory should be the one directly containing 132 | the headers. We `#include `, not `#include `. 133 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | ISC License 2 | 3 | Copyright (c) 2013, 2014 David Demelier 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any 6 | purpose with or without fee is hereby granted, provided that the above 7 | copyright notice and this permission notice appear in all copies. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Lua-SDL2 (SDL2 binding for Lua) 2 | ================================== 3 | 4 | Lua-SDL2 is a pure C binding of SDL2 to Lua 5.1, Lua 5.2, Lua 5.3, Lua 5.4, and 5 | LuaJIT. 6 | 7 | The current version is 2.1, compatible with SDL 2.0.1 - 2.0.5. 8 | 9 | Lua-SDL2 follows the [SemVer](https://semver.org) standard with regards to project 10 | versioning. 11 | 12 | Features 13 | ======== 14 | 15 | Lua-SDL2 is a portable binding of SDL2, written in pure C for efficiency. 16 | It tries to stay as close to SDL as possible, acting as a simple binding 17 | rather than attempting to re-design the interaction between the programmer 18 | and SDL. 19 | 20 | Lua-SDL2 takes full advantage of Lua's object-oriented capabilities wherever 21 | possible, allowing the programmer to fully leverage SDL's inherent 22 | object-oriented design. 23 | 24 | Lua-SDL2 is very well documented, with copious source-code comments, and a full 25 | API reference available at [the wiki](https://github.com/Tangent128/LuaSDL2/wiki/). 26 | 27 | Compatibility 28 | ============= 29 | 30 | Lua-SDL2 is designed to be as compatible as possible. The library has support 31 | for all the latest features of SDL2, while still compiling with SDL 2.0.1. 32 | 33 | If the library is compiled with a newer point release of SDL than what is 34 | listed here, the library should still function, simply without access to the 35 | newer features. 36 | 37 | Lua-SDL2 is compatible with: 38 | 39 | * Lua 5.1, 5.2, 5.3, 5.4 or LuaJIT 40 | * SDL 2.0.1 and greater 41 | 42 | Installing 43 | ========== 44 | 45 | If you have LuaRocks installed, 46 | 47 | $ luarocks install lua-sdl2 48 | 49 | Otherwise, read `INSTALL.md` for instructions to build it yourself. 50 | 51 | Website 52 | ======= 53 | 54 | The official website is hosted at [https://github.com/Tangent128/luasdl2](https://github.com/Tangent128/luasdl2). 55 | 56 | The current documentation is available at the associated 57 | [wiki](https://github.com/Tangent128/luasdl2/wiki/). 58 | 59 | Author and Maintainer 60 | ===================== 61 | 62 | The Lua-SDL2 library was written by [David Demelier](mailto:markand@malikania.fr). 63 | 64 | It is currently being maintained by [Joseph Wallace](mailto:tangent128@gmail.com). 65 | -------------------------------------------------------------------------------- /cmake/FindLua.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # FindLua.cmake -- find Lua versions 3 | # 4 | # Copyright (c) 2020 David Demelier 5 | # 6 | # Permission to use, copy, modify, and/or distribute this software for any 7 | # purpose with or without fee is hereby granted, provided that the above 8 | # copyright notice and this permission notice appear in all copies. 9 | # 10 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | # 18 | # Find bare Lua library, this modules defines: 19 | # 20 | # Lua_LIBRARY, the name of the library to link against. 21 | # Lua_LIBRARIES, alias to Lua_LIBRARY. 22 | # Lua_FOUND, true if found. 23 | # Lua_INCLUDE_DIR, where to find lua.h. 24 | # Lua_VERSION, the string version in the form x.y 25 | # Lua_VERSION_MAJOR, major version (e.g. 5 in Lua 5.3) 26 | # Lua_VERSION_MINOR, major version (e.g. 3 in Lua 5.3) 27 | # 28 | # The following imported targets will be defined: 29 | # 30 | # Lua::Lua 31 | # 32 | 33 | include(FindPackageHandleStandardArgs) 34 | 35 | find_path( 36 | Lua_INCLUDE_DIR 37 | NAMES lua.h 38 | PATH_SUFFIXES include/lua 39 | ) 40 | 41 | find_library( 42 | Lua_LIBRARY 43 | NAMES lua 44 | ) 45 | 46 | if (Lua_INCLUDE_DIR AND EXISTS "${Lua_INCLUDE_DIR}/lua.h") 47 | file(STRINGS "${Lua_INCLUDE_DIR}/lua.h" LUA_H REGEX "^#define LUA_VERSION_NUM.*$") 48 | 49 | string(REGEX MATCH "([0-9])[0-9]([0-9])" Lua_VERSION "${LUA_H}") 50 | string(REGEX REPLACE "([0-9])[0-9]([0-9])" "\\1.\\2" Lua_VERSION ${Lua_VERSION}) 51 | 52 | string(REGEX REPLACE "([0-9])\\.[0-9]" "\\1" Lua_VERSION_MAJOR ${Lua_VERSION}) 53 | string(REGEX REPLACE "[0-9]\\.([0-9])" "\\1" Lua_VERSION_MINOR ${Lua_VERSION}) 54 | endif () 55 | 56 | find_package_handle_standard_args( 57 | Lua 58 | REQUIRED_VARS Lua_LIBRARY Lua_INCLUDE_DIR 59 | VERSION_VAR Lua_VERSION 60 | HANDLE_COMPONENTS 61 | ) 62 | 63 | if (Lua_FOUND) 64 | set(Lua_INCLUDE_DIRS ${Lua_INCLUDE_DIR}) 65 | set(Lua_LIBRARIES ${Lua_LIBRARY}) 66 | 67 | if (NOT TARGET Lua::Lua) 68 | add_library(Lua::Lua UNKNOWN IMPORTED) 69 | set_target_properties( 70 | Lua::Lua 71 | PROPERTIES 72 | IMPORTED_LINK_INTERFACE_LANGUAGES "C" 73 | IMPORTED_LOCATION "${Lua_LIBRARY}" 74 | INTERFACE_INCLUDE_DIRECTORIES "${Lua_INCLUDE_DIRS}" 75 | ) 76 | endif () 77 | endif () 78 | 79 | mark_as_advanced(Lua_INCLUDE_DIR Lua_LIBRARY) 80 | -------------------------------------------------------------------------------- /cmake/FindLuaJIT.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # FindLuaJIT.cmake -- find LuaJIT 3 | # 4 | # Copyright (c) 2020 David Demelier 5 | # 6 | # Permission to use, copy, modify, and/or distribute this software for any 7 | # purpose with or without fee is hereby granted, provided that the above 8 | # copyright notice and this permission notice appear in all copies. 9 | # 10 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | # 18 | # Find LuaJIT library, this modules defines: 19 | # 20 | # LuaJIT_LIBRARY, the name of the library to link against. 21 | # LuaJIT_LIBRARIES, alias to Lua_LIBRARY. 22 | # LuaJIT_FOUND, true if found. 23 | # LuaJIT_INCLUDE_DIR, where to find lua.h. 24 | # LuaJIT_VERSION, the string version in the form x.y 25 | # LuaJIT_VERSION_MAJOR, major version (e.g. 5 in Lua 5.3) 26 | # LuaJIT_VERSION_MINOR, major version (e.g. 3 in Lua 5.3) 27 | # 28 | # The following imported targets will be defined: 29 | # 30 | # LuaJIT::LuaJIT 31 | # 32 | 33 | include(FindPackageHandleStandardArgs) 34 | 35 | find_path( 36 | LuaJIT_INCLUDE_DIR 37 | NAMES lua.h 38 | PATH_SUFFIXES include/luajit-2.0 39 | ) 40 | 41 | find_library( 42 | LuaJIT_LIBRARY 43 | NAMES luajit luajit-5.1 44 | ) 45 | 46 | if (LuaJIT_INCLUDE_DIR AND EXISTS "${LuaJIT_INCLUDE_DIR}/lua.h") 47 | file(STRINGS "${LuaJIT_INCLUDE_DIR}/lua.h" LUA_H REGEX "^#define LUA_VERSION_NUM.*$") 48 | 49 | string(REGEX MATCH "([0-9])[0-9]([0-9])" LuaJIT_VERSION "${LUA_H}") 50 | string(REGEX REPLACE "([0-9])[0-9]([0-9])" "\\1.\\2" LuaJIT_VERSION ${LuaJIT_VERSION}) 51 | 52 | string(REGEX REPLACE "([0-9])\\.[0-9]" "\\1" LuaJIT_VERSION_MAJOR ${LuaJIT_VERSION}) 53 | string(REGEX REPLACE "[0-9]\\.([0-9])" "\\1" LuaJIT_VERSION_MINOR ${LuaJIT_VERSION}) 54 | endif () 55 | 56 | find_package_handle_standard_args( 57 | LuaJIT 58 | REQUIRED_VARS LuaJIT_LIBRARY LuaJIT_INCLUDE_DIR 59 | VERSION_VAR LuaJIT_VERSION 60 | HANDLE_COMPONENTS 61 | ) 62 | 63 | if (LuaJIT_FOUND) 64 | set(LuaJIT_INCLUDE_DIRS ${LuaJIT_INCLUDE_DIR}) 65 | set(LuaJIT_LIBRARIES ${LuaJIT_LIBRARY}) 66 | 67 | if (NOT TARGET LuaJIT::LuaJIT) 68 | add_library(LuaJIT::LuaJIT UNKNOWN IMPORTED) 69 | set_target_properties( 70 | LuaJIT::LuaJIT 71 | PROPERTIES 72 | IMPORTED_LINK_INTERFACE_LANGUAGES "C" 73 | IMPORTED_LOCATION "${LuaJIT_LIBRARY}" 74 | INTERFACE_INCLUDE_DIRECTORIES "${LuaJIT_INCLUDE_DIRS}" 75 | ) 76 | endif () 77 | endif () 78 | 79 | mark_as_advanced(LuaJIT_INCLUDE_DIR LuaJIT_LIBRARY) 80 | -------------------------------------------------------------------------------- /cmake/FindSDL2.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # FindSDL2.cmake -- find SDL2 library and addons 3 | # 4 | # Copyright (c) 2020 David Demelier 5 | # 6 | # Permission to use, copy, modify, and/or distribute this software for any 7 | # purpose with or without fee is hereby granted, provided that the above 8 | # copyright notice and this permission notice appear in all copies. 9 | # 10 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | # 18 | # Find SDL2 library and components, this modules defines: 19 | # 20 | # SDL2_LIBRARY, the name of the library to link against. 21 | # SDL2_MAIN_LIBRARY, for SDL2main (if present). 22 | # SDL2_LIBRARIES, alias to SDL2_LIBRARY. 23 | # SDL2_FOUND, true if found. 24 | # SDL2_INCLUDE_DIR, where to find SDL.h. 25 | # 26 | # The following imported targets will be defined: 27 | # 28 | # SDL2::SDL2 29 | # SDL2::SDL2main (if present) 30 | # 31 | # This module also handle the following official SDL addons: 32 | # 33 | # - image 34 | # - mixer 35 | # - net 36 | # - ttf 37 | # 38 | # And thus, variables SDL2__LIBRARY, SDL2__INCLUDE_DIRS and SDL2:: 39 | # imported targets will be defined if they are found. 40 | # 41 | 42 | include(FindPackageHandleStandardArgs) 43 | 44 | # The official include convention is not . 45 | find_path( 46 | SDL2_INCLUDE_DIR 47 | NAMES SDL.h 48 | PATH_SUFFIXES include/SDL2 include 49 | ) 50 | 51 | find_library(SDL2_LIBRARY NAMES SDL2 libSDL2) 52 | find_library(SDL2_MAIN_LIBRARY NAMES SDL2main libSDL2main) 53 | 54 | # Standard components. 55 | foreach (c ${SDL2_FIND_COMPONENTS}) 56 | find_path( 57 | SDL2_${c}_INCLUDE_DIR 58 | NAMES SDL.h 59 | PATH_SUFFIXES include/SDL2 include 60 | ) 61 | 62 | find_library( 63 | SDL2_${c}_LIBRARY 64 | NAMES SDL2_${c} libSDL2_${c} 65 | ) 66 | 67 | if (NOT TARGET SDL2::${c} AND SDL2_${c}_LIBRARY) 68 | set(SDL2_${c}_FOUND TRUE) 69 | add_library(SDL2::${c} UNKNOWN IMPORTED) 70 | set_target_properties( 71 | SDL2::${c} 72 | PROPERTIES 73 | IMPORTED_LINK_INTERFACE_LANGUAGES "C" 74 | IMPORTED_LOCATION "${SDL2_${c}_LIBRARY}" 75 | INTERFACE_INCLUDE_DIRECTORIES "${SDL2_${c}_INCLUDE_DIRS}" 76 | ) 77 | endif () 78 | 79 | mark_as_advanced(SDL2_${c}_INCLUDE_DIR SDL2_${c}_LIBRARY) 80 | endforeach () 81 | 82 | find_package_handle_standard_args( 83 | SDL2 84 | REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR 85 | HANDLE_COMPONENTS 86 | ) 87 | 88 | if (SDL2_FOUND) 89 | set(SDL2_LIBRARIES ${SDL2_LIBRARY}) 90 | set(SDL2_INCLUDE_DIRS ${SDL2_INCLUDE_DIR}) 91 | 92 | if (NOT TARGET SDL2::SDL2) 93 | add_library(SDL2::SDL2 UNKNOWN IMPORTED) 94 | set_target_properties( 95 | SDL2::SDL2 96 | PROPERTIES 97 | IMPORTED_LINK_INTERFACE_LANGUAGES "C" 98 | IMPORTED_LOCATION "${SDL2_LIBRARY}" 99 | INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIRS}" 100 | ) 101 | endif () 102 | 103 | if (NOT TARGET SDL2::main AND SDL2_MAIN_LIBRARY) 104 | add_library(SDL2::main UNKNOWN IMPORTED) 105 | set_target_properties( 106 | SDL2::main 107 | PROPERTIES 108 | IMPORTED_LINK_INTERFACE_LANGUAGES "C" 109 | IMPORTED_LOCATION "${SDL2_MAIN_LIBRARY}" 110 | INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIRS}" 111 | ) 112 | endif () 113 | endif () 114 | 115 | mark_as_advanced(SDL2_INCLUDE_DIR SDL2_LIBRARY) 116 | -------------------------------------------------------------------------------- /cmake/FindSysQueue.cmake: -------------------------------------------------------------------------------- 1 | # - Locate and check sys/queue.h presence 2 | # 3 | # SYSQUEUE_FOUND - system has sys/queue.h 4 | # SYSQUEUE_SLIST - queue.h has SLIST macros 5 | # SYSQUEUE_STAILQ - queue.h has STAILQ macros 6 | # SYSQUEUE_LIST - queue.h has LIST macros 7 | # SYSQUEUE_TAILQ - queue.h has TAILQ macros 8 | # SYSQUEUE_SIMPLEQ - queue.h has SIMPLEQ macros 9 | # SYSQUEUE_CIRCLEQ - queue.h has CIRCLEQ macros 10 | # SYSQUEUE_TAILQ - queue.h has TAILQ macros 11 | # 12 | # Some macros are not available on every systems, these variables are 13 | # defined if they are found in the queue.h file 14 | # 15 | # SYSQUEUE_SLIST_FOREACH - queue.h has SLIST_FOREACH macros 16 | # SYSQUEUE_SLIST_FOREACH_SAFE - queue.h has SLIST_FOREACH_SAFE macros 17 | # SYSQUEUE_STAILQ_FOREACH - queue.h has STAILQ_FOREACH macros 18 | # SYSQUEUE_STAILQ_FOREACH - queue.h has STAILQ_FOREACH_SAFE macros 19 | # SYSQUEUE_LIST_FOREACH - queue.h has LIST_FOREACH macros 20 | # SYSQUEUE_LIST_FOREACH_SAFE - queue.h has LIST_FOREACH_SAFE macros 21 | # SYSQUEUE_TAILQ_FOREACH - queue.h has TAILQ_FOREACH macros 22 | # SYSQUEUE_TAILQ_FOREACH - queue.h has TAILQ_FOREACH_SAFE macros 23 | # 24 | 25 | include(CheckIncludeFile) 26 | include(CheckSymbolExists) 27 | 28 | check_include_file(sys/queue.h SYSQUEUE_FOUND) 29 | if (SYSQUEUE_FOUND) 30 | foreach (type "SLIST" "STAILQ" "LIST" "TAILQ" "SIMPLEQ" "CIRCLEQ") 31 | check_symbol_exists(${type}_HEAD sys/queue.h SYSQUEUE_${type}) 32 | 33 | if (SYSQUEUE_${type}) 34 | # Check for _FOREACH. 35 | check_symbol_exists( 36 | ${type}_FOREACH 37 | sys/queue.h 38 | SYSQUEUE_${type}_FOREACH 39 | ) 40 | 41 | # Check for _FOREACH_SAFE. 42 | check_symbol_exists( 43 | ${type}_FOREACH_SAFE 44 | sys/queue.h 45 | SYSQUEUE_${type}_FOREACH_SAFE 46 | ) 47 | endif () 48 | endforeach () 49 | endif () 50 | -------------------------------------------------------------------------------- /cmake/config.h.in: -------------------------------------------------------------------------------- 1 | #ifndef _CONFIG_H_ 2 | #define _CONFIG_H_ 3 | 4 | #define VERSION_BINDING_MAJOR @BINDING_MAJOR@ 5 | #define VERSION_BINDING_MINOR @BINDING_MINOR@ 6 | 7 | /* Portability checks */ 8 | #cmakedefine HAVE_DROPEVENT_WINDOW_ID 9 | 10 | #endif /* !_CONFIG_H_ */ 11 | -------------------------------------------------------------------------------- /common/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # CMakeLists.txt -- build system for LuaSDL2 3 | # 4 | # Copyright (c) 2013, 2014 David Demelier 5 | # 6 | # Permission to use, copy, modify, and/or distribute this software for any 7 | # purpose with or without fee is hereby granted, provided that the above 8 | # copyright notice and this permission notice appear in all copies. 9 | # 10 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | project(common C) 19 | 20 | set( 21 | SOURCES 22 | array.c 23 | array.h 24 | common.c 25 | common.h 26 | rwops.c 27 | rwops.h 28 | surface.c 29 | surface.h 30 | table.c 31 | table.h 32 | variant.c 33 | variant.h 34 | video.c 35 | video.h 36 | ) 37 | 38 | add_library(common OBJECT ${SOURCES}) 39 | set_target_properties(common PROPERTIES POSITION_INDEPENDENT_CODE TRUE) 40 | target_link_libraries(common SDL2::SDL2) 41 | target_include_directories( 42 | common 43 | PUBLIC 44 | ${Lua_INCLUDE_DIRS} 45 | ${LuaJIT_INCLUDE_DIRS} 46 | $ 47 | ) 48 | -------------------------------------------------------------------------------- /common/array.c: -------------------------------------------------------------------------------- 1 | /* 2 | * array.c -- manipulate dynamic arrays 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include "array.h" 24 | 25 | #define OFFSET(x) (arr->unit * (x)) 26 | 27 | static int grow(Array *); 28 | 29 | int 30 | arrayInit(Array *arr, size_t unit, size_t chksize) 31 | { 32 | if (unit == 0) 33 | return -1; 34 | 35 | arr->length = 0; 36 | arr->flags = 0; 37 | arr->unit = unit; 38 | arr->chksize = chksize; 39 | arr->size = OFFSET(arr->chksize); 40 | 41 | if ((arr->data = malloc(arr->size)) == NULL) 42 | return -1; 43 | 44 | if (arr->flags & ARRAY_CLEARBITS) 45 | memset(arr->data, 0, arr->size); 46 | 47 | return 0; 48 | } 49 | 50 | /* 51 | * Add to the head of array. NOTE: this may be very slow when adding a lot 52 | * of object (about 100000). If you need to add a lot of data please consider 53 | * using linked list instead. Returns -1 on failure or 0 on success. 54 | */ 55 | int 56 | arrayPush(Array *arr, const void *data) 57 | { 58 | if (grow(arr) < 0) 59 | return -1; 60 | 61 | memmove((char *)arr->data + arr->unit, arr->data, OFFSET(arr->length++)); 62 | memcpy((char *)arr->data, data, arr->unit); 63 | 64 | return 0; 65 | } 66 | 67 | /* 68 | * Insert the data at the specified index. The function returns -1 on 69 | * allocation failure or the position of the added element. 70 | */ 71 | int 72 | arrayInsert(Array *arr, const void *data, int index) 73 | { 74 | if (arr->flags & ARRAY_INSERTSAFE) 75 | if (index < 0 || index > arr->length) 76 | return -1; 77 | 78 | if (index < 0) 79 | return arrayPush(arr, data); 80 | if (index >= arr->length) 81 | return arrayAppend(arr, data); 82 | 83 | /* Good place */ 84 | memmove((char *)arr->data + OFFSET(index + 1), 85 | (char *)arr->data + OFFSET(index), OFFSET(arr->length++ - index)); 86 | memcpy((char *)arr->data + OFFSET(index), data, arr->unit); 87 | 88 | return index; 89 | } 90 | 91 | /* 92 | * Append the data to the end of array. Returns -1 on failure or the position 93 | * of the added element. 94 | */ 95 | int 96 | arrayAppend(Array *arr, const void *data) 97 | { 98 | if (grow(arr) < 0) 99 | return -1; 100 | 101 | memcpy((char *)arr->data + OFFSET(arr->length++), data, arr->unit); 102 | 103 | return (arr->length - 1); 104 | } 105 | 106 | /* 107 | * Remove the array's head. 108 | */ 109 | void 110 | arrayPop(Array *arr) 111 | { 112 | arrayRemovei(arr, 0); 113 | } 114 | 115 | /* 116 | * Remove the array's tail. 117 | */ 118 | void 119 | arrayUnqueue(Array *arr) 120 | { 121 | arrayRemovei(arr, arr->length - 1); 122 | } 123 | 124 | /* 125 | * Remove the data at the specified index. Bounds are checked. 126 | */ 127 | void 128 | arrayRemovei(Array *arr, int index) 129 | { 130 | if (arr->length > 0 && index >= 0 && index < arr->length) { 131 | if (arr->flags & ARRAY_FASTREMOVE) 132 | memmove((char *)arr->data + OFFSET(index), 133 | (char *)arr->data + OFFSET(--arr->length), 134 | arr->unit); 135 | else 136 | memmove((char *)arr->data + OFFSET(index), 137 | (char *)arr->data + OFFSET(index + 1), 138 | OFFSET(arr->length-- - index - 1)); 139 | } 140 | 141 | if (arr->flags & ARRAY_CLEARBITS) 142 | memset((char *)arr->data + OFFSET(arr->length), 0, arr->unit); 143 | } 144 | 145 | /* 146 | * Remove the object referenced by the `data' argument. Useful when you 147 | * don't know the index. 148 | */ 149 | void 150 | arrayRemovep(Array *arr, const void *data) 151 | { 152 | void *elm; 153 | int i; 154 | 155 | for (i = 0; i < arr->length; ++i) { 156 | elm = (char *)arr->data + OFFSET(i); 157 | 158 | if (memcmp(elm, data, arr->unit) == 0) { 159 | arrayRemovei(arr, i); 160 | break; 161 | } 162 | } 163 | } 164 | 165 | /* 166 | * Swap the two elements referenced by index `i1' and `i2'. This function needs 167 | * to allocate data to swap elements thus if the functions fails it returns -1 168 | * otherwise 0 is returned. 169 | */ 170 | int 171 | arraySwapi(Array *arr, int i1, int i2) 172 | { 173 | void *tmp; 174 | 175 | /* Out of bounds */ 176 | if (i1 >= arr->length || i1 < 0 || i2 >= arr->length || i2 < 0) 177 | return -1; 178 | 179 | if ((tmp = malloc(arr->unit)) == NULL) 180 | return -1; 181 | 182 | memcpy((char *)tmp, (char *)arr->data + OFFSET(i1), arr->unit); 183 | memcpy((char *)arr->data + OFFSET(i1), (char *)arr->data + OFFSET(i2), 184 | arr->unit); 185 | memcpy((char *)arr->data + OFFSET(i2), (char *)tmp, arr->unit); 186 | 187 | /* 188 | * Clear bytes for safety you probably don't want a password or 189 | * secure data to be left somewhere in the memory. 190 | */ 191 | 192 | if (arr->flags & ARRAY_CLEARBITS) 193 | memset(tmp, 0, arr->unit); 194 | free(tmp); 195 | 196 | return 0; 197 | } 198 | 199 | /* 200 | * Swap the two elements referenced by data `o1' and `o2'. This function 201 | * may be slow on large arrays since it must travel all the object 202 | * to find the indexes. 203 | */ 204 | int 205 | arraySwapp(Array *arr, const void *o1, const void *o2) 206 | { 207 | int found, i1, i2; 208 | 209 | for (i1 = found = 0; !found && i1 < arr->length; ++i1) 210 | found = memcmp((char *)arr->data + OFFSET(i1), o1, arr->unit) == 0; 211 | 212 | if (!found) 213 | return -1; 214 | 215 | for (i2 = found = 0; !found && i2 < arr->length; ++i2) 216 | found = memcmp((char *)arr->data + OFFSET(i2), o2, arr->unit) == 0; 217 | 218 | if (!found) 219 | return -1; 220 | 221 | return arraySwapi(arr, --i1, --i2); 222 | } 223 | 224 | /* 225 | * Apply the function `fn' on each object and give the optional `udata' 226 | * argument to the function too. 227 | */ 228 | void 229 | arrayMap(const Array *arr, ArrayMap fn, void *udata) 230 | { 231 | int i; 232 | 233 | for (i = 0; i < arr->length; ++i) 234 | fn((char *)arr->data + OFFSET(i), udata); 235 | } 236 | 237 | /* 238 | * Call qsort function to sort the array. 239 | */ 240 | void 241 | arraySort(Array *arr, ArrayCmp fn) 242 | { 243 | qsort(arr->data, arr->length, arr->unit, fn); 244 | } 245 | 246 | /* 247 | * Compare each object with the user supplied function. If the `fn' function 248 | * returns 1, 1 is returned and dst points to the correct object, dst should 249 | * be a pointer to a pointer of object, like (int **) for a array of int. 250 | */ 251 | int 252 | arrayFind(const Array *arr, ArrayCmp fn, void *dst, void *u) 253 | { 254 | int st, i; 255 | 256 | for (i = st = 0; i < arr->length && st != 1; ++i) 257 | st = fn((char *)arr->data + OFFSET(i), u); 258 | 259 | if (st && dst) 260 | *(char **)dst = (char *)arr->data + OFFSET(i - 1); 261 | 262 | return (st) ? i - 1 : -1; 263 | } 264 | 265 | void * 266 | arrayFirst(const Array *arr) 267 | { 268 | return arr->data; 269 | } 270 | 271 | void * 272 | arrayLast(const Array *arr) 273 | { 274 | if (arr->length == 0) 275 | return arrayFirst(arr); 276 | 277 | return (char *)arr->data + OFFSET(arr->length - 1); 278 | 279 | } 280 | 281 | void * 282 | arrayGet(const Array *arr, int idx) 283 | { 284 | if (idx < 0) 285 | return arrayFirst(arr); 286 | if (idx >= arr->length) 287 | return arrayLast(arr); 288 | 289 | return (char *)arr->data + OFFSET(idx); 290 | } 291 | 292 | /* 293 | * Erase every bytes and set the length to 0. 294 | */ 295 | void 296 | arrayClear(Array *arr) 297 | { 298 | memset(arr->data, 0, arr->size); 299 | arr->length = 0; 300 | } 301 | 302 | /* 303 | * Same as array_clear except it also free the array object. 304 | */ 305 | void 306 | arrayFree(Array *arr) 307 | { 308 | if (arr->flags & ARRAY_CLEARBITS) 309 | arrayClear(arr); 310 | 311 | free(arr->data); 312 | 313 | arr->length = 0; 314 | arr->data = NULL; 315 | arr->size = 0; 316 | } 317 | 318 | /* 319 | * Trim down the array to the correct size. 320 | */ 321 | void * 322 | ArrayTrim(Array *arr) 323 | { 324 | return realloc(arr->data, arr->length * arr->unit); 325 | } 326 | 327 | /* 328 | * Increate the array storage when it is full. If the buffer is fixed size 329 | * it returns -1 on full buffer otherwise 0 is returned if allocation 330 | * succeeded. 331 | */ 332 | static int 333 | grow(Array *arr) 334 | { 335 | if ((arr->size / arr->unit) > (size_t)arr->length) 336 | return 0; 337 | 338 | if (!(arr->flags & ARRAY_FIXED)) { 339 | if ((arr->data = realloc(arr->data, arr->size + 340 | OFFSET(arr->chksize))) == NULL) { 341 | arr->size = arr->length = 0; 342 | return -1; 343 | } 344 | 345 | arr->size += OFFSET(arr->chksize); 346 | } else 347 | return -1; 348 | 349 | return 0; 350 | } 351 | -------------------------------------------------------------------------------- /common/array.h: -------------------------------------------------------------------------------- 1 | /* 2 | * array.h -- manipulate dynamic arrays 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _ARRAY_H_ 20 | #define _ARRAY_H_ 21 | 22 | #include 23 | #include 24 | 25 | #ifndef ARRAY_DEFAULT_CHKSIZE 26 | #define ARRAY_DEFAULT_CHKSIZE 128 27 | #endif 28 | 29 | typedef enum { 30 | ARRAY_AUTO = 0, /* array grows automatically */ 31 | ARRAY_FIXED = (1 << 0), /* fixed size length */ 32 | ARRAY_FASTREMOVE = (1 << 1), /* use last object when removing */ 33 | ARRAY_CLEARBITS = (1 << 2), /* clear data when inserting/removing */ 34 | ARRAY_INSERTSAFE = (1 << 3) /* insertion must have valid indexes */ 35 | } ArrayFlags; 36 | 37 | typedef struct { 38 | int flags; /* (ro) array flags (default AUTO) */ 39 | void *data; /* (rw) array of data */ 40 | int length; /* (ro) number of element inside */ 41 | size_t size; /* (ro) current buffer size (allocated memory) */ 42 | size_t unit; /* (ro) unit size (sizeof the object) */ 43 | int chksize; /* (rw) chunk size (used when growing array) */ 44 | } Array; 45 | 46 | typedef void (*ArrayMap)(void *, void *); 47 | typedef int (*ArrayCmp)(const void *, const void *); 48 | 49 | #ifdef __cplusplus 50 | extern "C" { 51 | #endif 52 | 53 | int 54 | arrayInit(Array *, size_t, size_t); 55 | 56 | int 57 | arrayPush(Array *, const void *); 58 | 59 | int 60 | arrayInsert(Array *, const void *, int); 61 | 62 | int 63 | arrayAppend(Array *, const void *); 64 | 65 | void 66 | arrayPop(Array *); 67 | 68 | void 69 | arrayUnqueue(Array *); 70 | 71 | void 72 | arrayRemovei(Array *, int); 73 | 74 | void 75 | arrayRemovep(Array *, const void *); 76 | 77 | int 78 | arraySwapi(Array *, int, int); 79 | 80 | int 81 | arraySwapp(Array *, const void *, const void *); 82 | 83 | void 84 | arrayMap(const Array *, ArrayMap, void *); 85 | 86 | void 87 | arraySort(Array *, ArrayCmp); 88 | 89 | int 90 | arrayFind(const Array *, ArrayCmp, void *, void *); 91 | 92 | void * 93 | arrayFirst(const Array *); 94 | 95 | void * 96 | arrayGet(const Array *, int); 97 | 98 | void * 99 | arrayLast(const Array *); 100 | 101 | void 102 | arrayClear(Array *); 103 | 104 | void 105 | arrayFree(Array *); 106 | 107 | void * 108 | ArrayTrim(Array *); 109 | 110 | #define ARRAY_FOREACH(a, var, i) \ 111 | for (i = 0, (var) = arrayFirst((a)); \ 112 | i < (a)->length; \ 113 | (var) = arrayGet(a, ++i)) 114 | 115 | #ifdef __cplusplus 116 | } 117 | #endif 118 | 119 | #endif /* _ARRAY_H_ */ 120 | -------------------------------------------------------------------------------- /common/common.c: -------------------------------------------------------------------------------- 1 | /* 2 | * common.c -- common code for LuaSDL2 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "common.h" 25 | 26 | #if LUA_VERSION_NUM == 501 27 | 28 | void * 29 | luaL_testudata(lua_State *L, int index, const char *tname) 30 | { 31 | void *p = lua_touserdata(L, index); 32 | 33 | if (p != NULL) { 34 | if (lua_getmetatable(L, index)) { 35 | luaL_getmetatable(L, tname); 36 | 37 | if (!lua_rawequal(L, -1, -2)) 38 | p = NULL; 39 | 40 | lua_pop(L, 2); 41 | 42 | return p; 43 | } 44 | } 45 | 46 | return NULL; 47 | } 48 | 49 | void 50 | lua_rawsetp(lua_State *L, int index, void *p) 51 | { 52 | int realindex = ((index) < 0) ? (index) - 1 : (index); 53 | 54 | lua_pushlightuserdata(L, p); 55 | lua_insert(L, -2); 56 | lua_rawset(L, realindex); 57 | } 58 | 59 | #endif 60 | 61 | #if LUA_VERSION_NUM == 502 62 | 63 | int 64 | lua_geti(lua_State *L, int index, lua_Integer i) 65 | { 66 | index = lua_absindex(L, index); 67 | lua_pushinteger(L, i); 68 | lua_gettable(L, index); 69 | 70 | return lua_type(L, -1); 71 | } 72 | 73 | #endif 74 | 75 | void 76 | commonBindEnum(lua_State *L, 77 | int tindex, 78 | const char *tname, 79 | const CommonEnum *values) 80 | { 81 | int i; 82 | 83 | lua_createtable(L, 0, 0); 84 | 85 | for (i = 0; values[i].name != NULL; ++i) { 86 | lua_pushinteger(L, values[i].value); 87 | lua_setfield(L, -2, values[i].name); 88 | } 89 | 90 | if (tindex < 0) 91 | tindex --; 92 | 93 | lua_setfield(L, tindex, tname); 94 | } 95 | 96 | int 97 | commonGetEnum(lua_State *L, int tindex) 98 | { 99 | int value = 0; 100 | 101 | if (lua_type(L, tindex) == LUA_TNUMBER) { 102 | value = (int)lua_tonumber(L, tindex); 103 | } else if (lua_type(L, tindex) == LUA_TTABLE) { 104 | if (tindex < 0) 105 | tindex --; 106 | 107 | lua_pushnil(L); 108 | while (lua_next(L, tindex) != 0) { 109 | if (lua_type(L, -1) == LUA_TNUMBER) 110 | value |= lua_tointeger(L, -1); 111 | 112 | lua_pop(L, 1); 113 | } 114 | } 115 | 116 | return value; 117 | } 118 | 119 | void 120 | commonPushEnum(lua_State *L, int value, const CommonEnum *evalue) 121 | { 122 | int i; 123 | 124 | lua_createtable(L, 0, 0); 125 | 126 | for (i = 0; evalue[i].name != NULL; ++i) { 127 | /* 128 | * Put as a map like table[i] = i so it's cleaner and 129 | * more convenient for the user. The user is also able to reuse 130 | * the table. 131 | */ 132 | if (value & evalue[i].value) { 133 | lua_pushinteger(L, evalue[i].value); 134 | lua_rawseti(L, -2, evalue[i].value); 135 | } 136 | } 137 | } 138 | 139 | void 140 | commonBindObject(lua_State *L, const CommonObject *def) 141 | { 142 | luaL_newmetatable(L, def->name); 143 | 144 | if (def->metamethods != NULL) { 145 | #if LUA_VERSION_NUM >= 502 146 | luaL_setfuncs(L, def->metamethods, 0); 147 | #else 148 | luaL_register(L, NULL, def->metamethods); 149 | #endif 150 | } 151 | 152 | if (def->methods != NULL) { 153 | lua_createtable(L, 0, 0); 154 | #if LUA_VERSION_NUM >= 502 155 | luaL_setfuncs(L, def->methods, 0); 156 | #else 157 | luaL_register(L, NULL, def->methods); 158 | #endif 159 | lua_setfield(L, -2, "__index"); 160 | } 161 | 162 | lua_pop(L, 1); 163 | } 164 | 165 | void 166 | commonBindLibrary(lua_State *L, const luaL_Reg *functions) 167 | { 168 | #if LUA_VERSION_NUM >= 502 169 | luaL_setfuncs(L, functions, 0); 170 | #else 171 | luaL_register(L, NULL, functions); 172 | #endif 173 | } 174 | 175 | void 176 | commonNewLibrary(lua_State *L, const luaL_Reg *functions) 177 | { 178 | #if LUA_VERSION_NUM >= 502 179 | lua_createtable(L, 0, 0); 180 | luaL_setfuncs(L, functions, 0); 181 | #else 182 | lua_createtable(L, 0, 0); 183 | luaL_register(L, NULL, functions); 184 | #endif 185 | } 186 | 187 | CommonUserdata * 188 | commonPushUserdata(lua_State *L, const char *tname, void *data) 189 | { 190 | CommonUserdata *ptr; 191 | 192 | ptr = lua_newuserdata(L, sizeof (CommonUserdata)); 193 | ptr->mustdelete = 1; 194 | ptr->data = data; 195 | 196 | #if LUA_VERSION_NUM >= 502 197 | luaL_setmetatable(L, tname); 198 | #else 199 | luaL_getmetatable(L, tname); 200 | lua_setmetatable(L, -2); 201 | #endif 202 | 203 | return ptr; 204 | } 205 | 206 | CommonUserdata * 207 | commonGetUserdata(lua_State *L, int index, const char *tname) 208 | { 209 | return luaL_checkudata(L, index, tname); 210 | } 211 | 212 | int 213 | commonPushSDLError(lua_State *L, int count) 214 | { 215 | int i; 216 | 217 | for (i = 0; i < count; ++i) 218 | lua_pushnil(L); 219 | 220 | lua_pushstring(L, SDL_GetError()); 221 | 222 | return count + 1; 223 | } 224 | 225 | int 226 | commonPushErrno(lua_State *L, int count) 227 | { 228 | int i; 229 | 230 | for (i = 0; i < count; ++i) 231 | lua_pushnil(L); 232 | 233 | lua_pushstring(L, strerror(errno)); 234 | 235 | return count + 1; 236 | } 237 | 238 | int 239 | commonPush(lua_State *L, const char *fmt, ...) 240 | { 241 | va_list ap; 242 | const char *p; 243 | int count = 0; 244 | 245 | va_start(ap, fmt); 246 | 247 | for (p = fmt; *p != '\0'; ++p) { 248 | switch (*p) { 249 | case 'i': 250 | lua_pushinteger(L, va_arg(ap, int)); 251 | ++ count; 252 | break; 253 | case 'd': 254 | lua_pushnumber(L, va_arg(ap, double)); 255 | ++ count; 256 | break; 257 | case 's': 258 | lua_pushstring(L, va_arg(ap, const char *)); 259 | ++ count; 260 | break; 261 | case 'b': 262 | lua_pushboolean(L, va_arg(ap, int)); 263 | ++ count; 264 | break; 265 | case 'l': 266 | lua_pushinteger(L, va_arg(ap, long)); 267 | ++ count; 268 | break; 269 | case 'n': 270 | lua_pushnil(L); 271 | ++ count; 272 | break; 273 | case 'p': 274 | { 275 | const char *tname = va_arg(ap, const char *); 276 | void *udata = va_arg(ap, void *); 277 | 278 | commonPushUserdata(L, tname, udata); 279 | ++ count; 280 | } 281 | break; 282 | default: 283 | break; 284 | } 285 | } 286 | 287 | return count; 288 | } 289 | -------------------------------------------------------------------------------- /common/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * common.h -- common code for lua-SDL2 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * Copyright (c) 2014 Joseph Wallace 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice appear in all copies. 10 | * 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | */ 19 | 20 | #ifndef _COMMON_H_ 21 | #define _COMMON_H_ 22 | 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | /* 32 | * Portability bits 33 | */ 34 | #if defined(_WIN32) 35 | # define EXPORT __declspec(dllexport) 36 | # define strdup _strdup 37 | #else 38 | # define EXPORT 39 | #endif 40 | 41 | /* 42 | * Portability bits for different Lua versions 43 | */ 44 | #if LUA_VERSION_NUM == 501 45 | 46 | # define LUA_OK 0 47 | # define lua_load(l, r, d, c, m) lua_load(l, r, d, c) 48 | 49 | void * 50 | luaL_testudata(lua_State *L, int index, const char *tname); 51 | 52 | void 53 | lua_rawsetp(lua_State *L, int index, void *key); 54 | 55 | #endif 56 | 57 | #if LUA_VERSION_NUM == 502 58 | 59 | #define lua_getuservalue(L, i) (lua_getuservalue((L), (i)), lua_type((L), -1)) 60 | 61 | int 62 | lua_geti(lua_State *L, int index, lua_Integer i); 63 | 64 | #endif 65 | 66 | #if LUA_VERSION_NUM < 503 67 | 68 | # define lua_dump(l, w, d, s) lua_dump(l, w, d) 69 | 70 | #endif 71 | 72 | /** 73 | * @struct common_evalue 74 | * @brief bind C enum as tables to Lua 75 | * 76 | * This is used with commonBindEnum(). 77 | * 78 | * @see commonBindEnum 79 | */ 80 | typedef struct { 81 | const char *name; /*! the field name */ 82 | int value; /*! the integer value */ 83 | } CommonEnum; 84 | 85 | /** 86 | * @CommonObject 87 | * @brief bind a C object to Lua 88 | * 89 | * This is used with commonBindObject(). 90 | * 91 | * @see commonBindObject 92 | */ 93 | typedef struct { 94 | const char *name; /*! metatable name */ 95 | const luaL_Reg *methods; /*! methods (optional) */ 96 | const luaL_Reg *metamethods; /*! metamethods (optional) */ 97 | } CommonObject; 98 | 99 | /** 100 | * Wrapper for SDL object to Lua userdata. Some objects must be passed 101 | * so that they will not be freed, for instance SDL_GetWindowSurface() returns 102 | * a pointer that should not be freed while SDL_Surface objects has a __gc 103 | * that destroy the object. 104 | * 105 | * So any object should be passed as common_userdata so we know if we should 106 | * really delete the object or just let it live. 107 | */ 108 | typedef struct { 109 | int mustdelete; /*! tells if we should delete it */ 110 | void *data; /*! the data itself */ 111 | } CommonUserdata; 112 | 113 | /** 114 | * Bind a C enum as a table to Lua. 115 | * 116 | * @param L the Lua state 117 | * @param tindex the table index where to set the table 118 | * @param tname the new table name as tindex new field 119 | * @param evalues the values 120 | */ 121 | void 122 | commonBindEnum(lua_State *L, 123 | int tindex, 124 | const char *tname, 125 | const CommonEnum *values); 126 | 127 | /** 128 | * Get a enumeration from a Lua table. 129 | * 130 | * @param L the Lua state 131 | * @param tindex the table index 132 | * @return the value or 0 133 | */ 134 | int 135 | commonGetEnum(lua_State *L, int tindex); 136 | 137 | /** 138 | * Push a enumeration as a map of enum to bool. That is if flag A is set and B 139 | * too on value, the pushed table will looks like this: 140 | * 141 | * table[A] = true 142 | * table[B] = true 143 | * 144 | * @param L the Lua state 145 | * @param value the value 146 | * @param evalue the enumeration to check 147 | */ 148 | void 149 | commonPushEnum(lua_State *L, int value, const CommonEnum *evalue); 150 | 151 | /** 152 | * Bind an object to Lua. 153 | * 154 | * @param L the Lua state 155 | * @param def the object definition 156 | */ 157 | void 158 | commonBindObject(lua_State *L, const CommonObject *def); 159 | 160 | /** 161 | * This function binds all functions to the already created table SDL. 162 | * 163 | * @param L the Lua state 164 | * @param functions the functions 165 | */ 166 | void 167 | commonBindLibrary(lua_State *L, const luaL_Reg *functions); 168 | 169 | /** 170 | * Create a table and fills the functions in it. 171 | * 172 | * @param L the Lua state 173 | * @param functions the functions 174 | */ 175 | void 176 | commonNewLibrary(lua_State *L, const luaL_Reg *functions); 177 | 178 | /** 179 | * Push a SDL object to Lua as an userdata. By default, the object 180 | * is set to be deleted. 181 | * 182 | * @param L the Lua state 183 | * @param tname the metatable name to use 184 | * @param data the pointer to the data 185 | * @return the new created object 186 | */ 187 | CommonUserdata * 188 | commonPushUserdata(lua_State *L, const char *tname, void *data); 189 | 190 | /** 191 | * Get a SDL object from Lua. 192 | * 193 | * @param L the Lua state 194 | * @param index the index 195 | * @param tname the object metatable name 196 | * @return the object or raise an error 197 | */ 198 | CommonUserdata * 199 | commonGetUserdata(lua_State *L, int index, const char *tname); 200 | 201 | /** 202 | * Pushes count * nil + the SDL_GetError() message. 203 | * 204 | * @param L the Lua state 205 | * @param count number of nil to pushes before 206 | * @return count 207 | */ 208 | int 209 | commonPushSDLError(lua_State *L, int count); 210 | 211 | /** 212 | * Pushes the errno error. 213 | * 214 | * @param L the Lua state 215 | * @param count number of nil to pushes before 216 | * @return count 217 | */ 218 | int 219 | commonPushErrno(lua_State *L, int count); 220 | 221 | /** 222 | * Convenient wrapper for pushing values. 223 | * Format supported: 224 | * i -> integer 225 | * d -> double 226 | * s -> string 227 | * b -> boolean 228 | * l -> long 229 | * n -> nil (no arg) 230 | * p -> userdata, userdata-name (two args) 231 | * 232 | * @param L the Lua state 233 | * @param fmt the format 234 | * @return the number of values pushed 235 | */ 236 | int 237 | commonPush(lua_State *L, const char *fmt, ...); 238 | 239 | #define commonGetAs(L, index, name, type) \ 240 | ((type)commonGetUserdata(L, index, name)->data) 241 | 242 | #endif /* !_COMMON_H_ */ 243 | -------------------------------------------------------------------------------- /common/rwops.h: -------------------------------------------------------------------------------- 1 | /* 2 | * rwops.h -- callback managed file operations 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _RWOPS_H_ 20 | #define _RWOPS_H_ 21 | 22 | #include "common.h" 23 | 24 | #define RWOpsName RWOps.name 25 | 26 | extern const luaL_Reg RWOpsFunctions[]; 27 | 28 | extern const CommonObject RWOps; 29 | 30 | extern const CommonEnum RWOpsSeek[]; 31 | 32 | extern const CommonEnum RWOpsType[]; 33 | 34 | #endif /* !_RWOPS_H_ */ 35 | -------------------------------------------------------------------------------- /common/surface.h: -------------------------------------------------------------------------------- 1 | /* 2 | * surface.h -- legacy surfaces support 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _SURFACE_H_ 20 | #define _SURFACE_H_ 21 | 22 | #include 23 | 24 | #define SurfaceName Surface.name 25 | 26 | extern const luaL_Reg SurfaceFunctions[]; 27 | 28 | extern const CommonEnum BlendMode[]; 29 | 30 | extern const CommonObject Surface; 31 | 32 | #endif /* !_SURFACE_H_ */ 33 | -------------------------------------------------------------------------------- /common/table.c: -------------------------------------------------------------------------------- 1 | /* 2 | * table.c -- table helpers 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include "table.h" 20 | 21 | int 22 | tableIsType(lua_State *L, int idx, const char *name, int type) 23 | { 24 | int ret; 25 | 26 | lua_getfield(L, idx, name); 27 | ret = lua_type(L, -1); 28 | lua_pop(L, 1); 29 | 30 | return ret == type; 31 | } 32 | 33 | CommonUserdata * 34 | tableGetUserdata(lua_State *L, int idx, const char *field, const char *tname) 35 | { 36 | CommonUserdata *ptr = NULL; 37 | 38 | lua_getfield(L, idx, field); 39 | ptr = luaL_checkudata(L, -1, tname); 40 | lua_pop(L, 1); 41 | 42 | return ptr; 43 | } 44 | 45 | int 46 | tableGetInt(lua_State *L, int idx, const char *name) 47 | { 48 | int ret; 49 | 50 | lua_getfield(L, idx, name); 51 | 52 | if (lua_type(L, -1) == LUA_TNUMBER) 53 | ret = lua_tointeger(L, -1); 54 | else 55 | ret = 0; 56 | 57 | lua_pop(L, 1); 58 | 59 | return ret; 60 | } 61 | 62 | double 63 | tableGetDouble(lua_State *L, int idx, const char *name) 64 | { 65 | double ret; 66 | 67 | lua_getfield(L, idx, name); 68 | 69 | if (lua_type(L, -1) == LUA_TNUMBER) 70 | ret = lua_tonumber(L, -1); 71 | else 72 | ret = 0; 73 | 74 | lua_pop(L, 1); 75 | 76 | return ret; 77 | } 78 | 79 | int 80 | tableGetEnum(lua_State *L, int idx, const char *name) 81 | { 82 | int ret; 83 | 84 | lua_getfield(L, idx, name); 85 | 86 | if (lua_type(L, -1) == LUA_TTABLE) 87 | ret = commonGetEnum(L, -1); 88 | else 89 | ret = 0; 90 | 91 | lua_pop(L, 1); 92 | 93 | return ret; 94 | } 95 | 96 | const char * 97 | tableGetString(lua_State *L, int idx, const char *name) 98 | { 99 | const char *ret; 100 | 101 | lua_getfield(L, idx, name); 102 | 103 | if (lua_type(L, -1) == LUA_TSTRING) 104 | ret = lua_tostring(L, -1); 105 | else 106 | ret = NULL; 107 | 108 | lua_pop(L, 1); 109 | 110 | return ret; 111 | } 112 | 113 | const char * 114 | tableGetStringl(lua_State *L, int idx, const char *name, size_t *length) 115 | { 116 | const char *ret; 117 | 118 | lua_getfield(L, idx, name); 119 | 120 | if (lua_type(L, -1) == LUA_TSTRING) 121 | ret = lua_tolstring(L, -1, length); 122 | else 123 | ret = NULL; 124 | 125 | lua_pop(L, 1); 126 | 127 | return ret; 128 | } 129 | 130 | int 131 | tableGetBool(lua_State *L, int idx, const char *name) 132 | { 133 | int ret = 0; 134 | 135 | lua_getfield(L, idx, name); 136 | ret = lua_toboolean(L, -1); 137 | lua_pop(L, 1); 138 | 139 | return ret; 140 | } 141 | 142 | void 143 | tableSetInt(lua_State *L, int idx, const char *name, int value) 144 | { 145 | if (idx < 0) 146 | idx --; 147 | 148 | lua_pushinteger(L, value); 149 | lua_setfield(L, idx, name); 150 | } 151 | 152 | void 153 | tableSetDouble(lua_State *L, int idx, const char *name, double value) 154 | { 155 | if (idx < 0) 156 | idx --; 157 | 158 | lua_pushnumber(L, value); 159 | lua_setfield(L, idx, name); 160 | } 161 | 162 | void 163 | tableSetString(lua_State *L, int idx, const char *name, const char *value) 164 | { 165 | if (idx < 0) 166 | idx --; 167 | 168 | lua_pushstring(L, value); 169 | lua_setfield(L, idx, name); 170 | } 171 | 172 | void 173 | tableSetStringl(lua_State *L, int idx, const char *name, const char *value, int length) 174 | { 175 | if (idx < 0) 176 | idx --; 177 | 178 | lua_pushlstring(L, value, length); 179 | lua_setfield(L, idx, name); 180 | } 181 | 182 | void 183 | tableSetBool(lua_State *L, int idx, const char *name, int value) 184 | { 185 | if (idx < 0) 186 | idx --; 187 | 188 | lua_pushboolean(L, value); 189 | lua_setfield(L, idx, name); 190 | } 191 | 192 | void 193 | tableSetEnum(lua_State *L, 194 | int idx, 195 | int value, 196 | const CommonEnum *evalue, 197 | const char *name) 198 | { 199 | commonPushEnum(L, value, evalue); 200 | 201 | if (idx < 0) 202 | idx --; 203 | 204 | lua_setfield(L, idx, name); 205 | } 206 | -------------------------------------------------------------------------------- /common/table.h: -------------------------------------------------------------------------------- 1 | /* 2 | * table.h -- table helpers 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _TABLE_H_ 20 | #define _TABLE_H_ 21 | 22 | #include "common.h" 23 | 24 | /** 25 | * Check if a table field is of a type. 26 | * 27 | * @param L the Lua state 28 | * @param idx the table index 29 | * @param name the field name 30 | * @param type the Lua type to test 31 | * @return true if they equals 32 | */ 33 | int 34 | tableIsType(lua_State *L, int idx, const char *name, int type); 35 | 36 | /** 37 | * Just like luaL_checktype() but for table fields. Also raises an error 38 | * if not the wanted userdata. 39 | * 40 | * @param L the Lua state 41 | * @param idx the table index 42 | * @param field the field name 43 | * @param tname the metatable name 44 | * @return the object 45 | */ 46 | CommonUserdata * 47 | tableGetUserdata(lua_State *L, int idx, const char *field, const char *tname); 48 | 49 | /** 50 | * Get a integer from a table. 51 | * 52 | * @param L the Lua state 53 | * @param idx the table index 54 | * @param name the field name 55 | * @return the value or 0 56 | */ 57 | int 58 | tableGetInt(lua_State *L, int idx, const char *name); 59 | 60 | /** 61 | * Get a double from a table. 62 | * 63 | * @param L the Lua state 64 | * @param idx the table index 65 | * @param name the field name 66 | * @return the value or 0 67 | */ 68 | double 69 | tableGetDouble(lua_State *L, int idx, const char *name); 70 | 71 | /** 72 | * Similar to tableGetEnum() but from a table field. 73 | * 74 | * @param L the Lua state 75 | * @param idx the table index 76 | * @param name the field name 77 | * @return the value or 0 78 | * @see tableGetEnum 79 | */ 80 | int 81 | tableGetEnum(lua_State *L, int idx, const char *name); 82 | 83 | /** 84 | * Get a string from a table. 85 | * 86 | * @param L the Lua state 87 | * @param idx the table index 88 | * @param name the field name 89 | * @return the value or NULL 90 | */ 91 | const char * 92 | tableGetString(lua_State *L, int idx, const char *name); 93 | 94 | /** 95 | * Get a string from a table. 96 | * 97 | * @param L the Lua state 98 | * @param idx the table index 99 | * @param name the field name 100 | * @param length the string length 101 | * @return the value or NULL 102 | */ 103 | const char * 104 | tableGetStringl(lua_State *L, int idx, const char *name, size_t *length); 105 | 106 | /** 107 | * Get a bool from a table. 108 | * 109 | * @param L the Lua state 110 | * @param idx the table index 111 | * @param name the field name 112 | * @return the value or 0 113 | */ 114 | int 115 | tableGetBool(lua_State *L, int idx, const char *name); 116 | 117 | /** 118 | * Set a integer field to a table. 119 | * 120 | * @param L the Lua state 121 | * @param idx the table index 122 | * @param name the field name 123 | * @param value the value 124 | */ 125 | void 126 | tableSetInt(lua_State *L, int idx, const char *name, int value); 127 | 128 | /** 129 | * Set a double as a field 130 | * 131 | * @param L the Lua state 132 | * @param idx the table index 133 | * @param name the field name 134 | * @param value the value 135 | */ 136 | void 137 | tableSetDouble(lua_State *L, int idx, const char *name, double value); 138 | 139 | /** 140 | * Set a string field to a table. 141 | * 142 | * @param L the Lua state 143 | * @param idx the table index 144 | * @param name the field name 145 | * @param value the value 146 | */ 147 | void 148 | tableSetString(lua_State *L, int idx, const char *name, const char *value); 149 | 150 | /** 151 | * Set a string field to a table but with specific length. Useful for string 152 | * which don't finish by '\0'. 153 | * 154 | * @param L the Lua state 155 | * @param idx the table index 156 | * @param name the field name 157 | * @param value the value 158 | * @param length the string length 159 | */ 160 | void 161 | tableSetStringl(lua_State *L, int idx, const char *name, const char *value, int length); 162 | 163 | /** 164 | * Set a boolean field to a table. 165 | * 166 | * @param L the Lua state 167 | * @param idx the table index 168 | * @param name the field name 169 | * @param value the value 170 | */ 171 | void 172 | tableSetBool(lua_State *L, int idx, const char *name, int value); 173 | 174 | /** 175 | * Set an enumeration to a table field. 176 | * 177 | * @param L the Lua state 178 | * @param idx the table index 179 | * @param value the value 180 | * @param evalue the enumeration to check 181 | * @param name the field name 182 | */ 183 | void 184 | tableSetEnum(lua_State *L, 185 | int idx, 186 | int value, 187 | const CommonEnum *evalue, 188 | const char *name); 189 | 190 | #endif /* !_TABLE_H_ */ 191 | -------------------------------------------------------------------------------- /common/variant.c: -------------------------------------------------------------------------------- 1 | /* 2 | * variant.c -- a Lua variant value 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | #include "variant.h" 23 | 24 | Variant * 25 | variantGet(lua_State *L, int index) 26 | { 27 | Variant *v; 28 | int type; 29 | 30 | if ((type = lua_type(L, index)) == LUA_TNIL) 31 | return NULL; 32 | 33 | if ((v = calloc(1, sizeof (Variant))) == NULL) 34 | return NULL; 35 | 36 | v->type = type; 37 | switch (v->type) { 38 | case LUA_TNUMBER: 39 | v->data.number = lua_tonumber(L, index); 40 | break; 41 | case LUA_TSTRING: 42 | { 43 | const char *str; 44 | size_t length; 45 | 46 | str = lua_tolstring(L, index, &length); 47 | if ((v->data.string.data = malloc(length)) == NULL) { 48 | free(v); 49 | return NULL; 50 | } 51 | 52 | /* Copy the string which may have embedded '\0' */ 53 | v->data.string.length = length; 54 | memcpy(v->data.string.data, str, length); 55 | } 56 | break; 57 | case LUA_TBOOLEAN: 58 | v->data.boolean = lua_toboolean(L, index); 59 | break; 60 | case LUA_TTABLE: 61 | { 62 | STAILQ_INIT(&v->data.table); 63 | 64 | if (index < 0) 65 | -- index; 66 | 67 | lua_pushnil(L); 68 | while (lua_next(L, index)) { 69 | VariantPair *pair = malloc(sizeof (VariantPair)); 70 | 71 | if (pair == NULL) { 72 | lua_pop(L, 1); 73 | variantFree(v); 74 | return NULL; 75 | } 76 | 77 | pair->key = variantGet(L, -2); 78 | pair->value = variantGet(L, -1); 79 | 80 | if (pair->key == NULL || pair->value == NULL) { 81 | lua_pop(L, 1); 82 | variantFree(pair->key); 83 | variantFree(pair->value); 84 | variantFree(v); 85 | free(pair); 86 | break; 87 | } 88 | 89 | lua_pop(L, 1); 90 | STAILQ_INSERT_TAIL(&v->data.table, pair, link); 91 | } 92 | } 93 | break; 94 | } 95 | 96 | return v; 97 | } 98 | 99 | void 100 | variantPush(lua_State *L, const Variant *v) 101 | { 102 | if (v == NULL) 103 | return; 104 | 105 | switch (v->type) { 106 | case LUA_TNUMBER: 107 | lua_pushnumber(L, v->data.number); 108 | break; 109 | case LUA_TSTRING: 110 | lua_pushlstring(L, v->data.string.data, v->data.string.length); 111 | break; 112 | case LUA_TBOOLEAN: 113 | lua_pushboolean(L, v->data.boolean); 114 | break; 115 | case LUA_TTABLE: 116 | { 117 | VariantPair *pair; 118 | 119 | lua_createtable(L, 0, 0); 120 | 121 | STAILQ_FOREACH(pair, &v->data.table, link) { 122 | variantPush(L, pair->key); 123 | variantPush(L, pair->value); 124 | lua_settable(L, -3); 125 | } 126 | } 127 | break; 128 | default: 129 | break; 130 | } 131 | } 132 | 133 | void 134 | variantFree(Variant *v) 135 | { 136 | VariantPair *t, *tmp; 137 | 138 | if (v == NULL) 139 | return; 140 | 141 | switch (v->type) { 142 | case LUA_TSTRING: 143 | free(v->data.string.data); 144 | break; 145 | case LUA_TTABLE: 146 | STAILQ_FOREACH_SAFE(t, &v->data.table, link, tmp) { 147 | variantFree(t->key); 148 | variantFree(t->value); 149 | free(t); 150 | } 151 | break; 152 | default: 153 | break; 154 | } 155 | 156 | free(v); 157 | } 158 | -------------------------------------------------------------------------------- /common/variant.h: -------------------------------------------------------------------------------- 1 | /* 2 | * variant.h -- a Lua variant value 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _VARIANT_H_ 20 | #define _VARIANT_H_ 21 | 22 | #include 23 | 24 | #include 25 | 26 | typedef struct variant_pair { 27 | struct variant *key; 28 | struct variant *value; 29 | 30 | STAILQ_ENTRY(variant_pair) link; 31 | } VariantPair; 32 | 33 | typedef STAILQ_HEAD(variant_pairs, variant_pair) VariantPairs; 34 | 35 | typedef struct variant { 36 | int type; 37 | 38 | union { 39 | char boolean; 40 | lua_Number number; 41 | VariantPairs table; 42 | 43 | struct { 44 | char *data; 45 | int length; 46 | } string; 47 | } data; 48 | 49 | /* Link for list */ 50 | STAILQ_ENTRY(variant) link; 51 | } Variant; 52 | 53 | typedef STAILQ_HEAD(variant_queue, variant) VariantQueue; 54 | 55 | Variant * 56 | variantGet(lua_State *L, int index); 57 | 58 | void 59 | variantPush(lua_State *L, const Variant *v); 60 | 61 | void 62 | variantFree(Variant *v); 63 | 64 | #endif /* !_VARIANT_H_ */ 65 | -------------------------------------------------------------------------------- /common/video.c: -------------------------------------------------------------------------------- 1 | /* 2 | * video.c -- video initialization and display management 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | 23 | #include "table.h" 24 | #include "video.h" 25 | 26 | /* -------------------------------------------------------- 27 | * Tables callbacks for reading 28 | * -------------------------------------------------------- */ 29 | 30 | typedef int (*TableReadFunc)(lua_State *, Array *); 31 | 32 | static int 33 | readRects(lua_State *L, Array *rects) 34 | { 35 | SDL_Rect r; 36 | 37 | /* Verify the point as a table */ 38 | if (lua_type(L, -1) != LUA_TTABLE) 39 | return 0; 40 | 41 | r.w = tableGetInt(L, -1, "w"); 42 | r.h = tableGetInt(L, -1, "h"); 43 | r.x = tableGetInt(L, -1, "x"); 44 | r.y = tableGetInt(L, -1, "y"); 45 | 46 | return arrayAppend(rects, &r) != -1; 47 | } 48 | 49 | static int 50 | readPoints(lua_State *L, Array *points) 51 | { 52 | SDL_Point p; 53 | 54 | /* Verify the point as a table */ 55 | if (lua_type(L, -1) != LUA_TTABLE) 56 | return 0; 57 | 58 | p.x = tableGetInt(L, -1, "x"); 59 | p.y = tableGetInt(L, -1, "y"); 60 | 61 | return arrayAppend(points, &p) != -1; 62 | } 63 | 64 | static int 65 | readColors(lua_State *L, Array *colors) 66 | { 67 | SDL_Color color; 68 | 69 | color = videoGetColorRGB(L, -1); 70 | 71 | return arrayAppend(colors, &color) != -1; 72 | } 73 | 74 | /** 75 | * This is a generic function for reading tables to fill an array. It calls 76 | * the function `func' for entry in the array. 77 | * 78 | * The function func should return 0 if we can continue, if the function 79 | * return -1, the array is free'd and we also return -1 to the caller. 80 | * 81 | * @param L the Lua state 82 | * @param index the table index 83 | * @param array the array to fill 84 | * @param unit the size of object 85 | * @param func the function to call 86 | * @return 0 on success and -1 on failure 87 | */ 88 | static int 89 | readTable(lua_State *L, int index, Array *array, size_t unit, TableReadFunc func) 90 | { 91 | int ok = 1; 92 | 93 | luaL_checktype(L, index, LUA_TTABLE); 94 | 95 | /* No memory */ 96 | if (arrayInit(array, unit, 32) < 0) 97 | return -1; 98 | 99 | if (index < 0) 100 | index --; 101 | 102 | lua_pushnil(L); 103 | while (lua_next(L, index) != 0 && ok) { 104 | ok = func(L, array); 105 | lua_pop(L, 1); 106 | } 107 | 108 | /* Should not be needed, but in case of array.c update */ 109 | if (!ok) 110 | arrayFree(array); 111 | 112 | return (ok) ? 0 : -1; 113 | } 114 | 115 | /* -------------------------------------------------------- 116 | * Shared functions 117 | * -------------------------------------------------------- */ 118 | 119 | void 120 | videoPushRect(lua_State *L, const SDL_Rect *rect) 121 | { 122 | lua_createtable(L, 4, 4); 123 | 124 | tableSetInt(L, -1, "w", rect->w); 125 | tableSetInt(L, -1, "h", rect->h); 126 | tableSetInt(L, -1, "x", rect->x); 127 | tableSetInt(L, -1, "y", rect->y); 128 | } 129 | 130 | void 131 | videoGetRect(lua_State *L, int index, SDL_Rect *rect) 132 | { 133 | luaL_checktype(L, index, LUA_TTABLE); 134 | 135 | rect->w = tableGetInt(L, index, "w"); 136 | rect->h = tableGetInt(L, index, "h"); 137 | rect->x = tableGetInt(L, index, "x"); 138 | rect->y = tableGetInt(L, index, "y"); 139 | } 140 | 141 | int 142 | videoGetRects(lua_State *L, int index, Array *rects) 143 | { 144 | return readTable(L, index, rects, sizeof (SDL_Rect), readRects); 145 | } 146 | 147 | void 148 | videoPushPoint(lua_State *L, const SDL_Point *point) 149 | { 150 | lua_createtable(L, 2, 2); 151 | 152 | tableSetInt(L, -1, "x", point->x); 153 | tableSetInt(L, -1, "y", point->y); 154 | } 155 | 156 | void 157 | videoGetPoint(lua_State *L, int index, SDL_Point *point) 158 | { 159 | luaL_checktype(L, index, LUA_TTABLE); 160 | 161 | point->x = tableGetInt(L, index, "x"); 162 | point->y = tableGetInt(L, index, "y"); 163 | } 164 | 165 | int 166 | videoGetPoints(lua_State *L, int index, Array *points) 167 | { 168 | return readTable(L, index, points, sizeof (SDL_Point), readPoints); 169 | } 170 | 171 | void 172 | videoGetLine(lua_State *L, int index, Line *line) 173 | { 174 | luaL_checktype(L, index, LUA_TTABLE); 175 | 176 | line->x1 = tableGetInt(L, index, "x1"); 177 | line->y1 = tableGetInt(L, index, "y1"); 178 | line->x2 = tableGetInt(L, index, "x2"); 179 | line->y2 = tableGetInt(L, index, "y2"); 180 | } 181 | 182 | /* 183 | * Deprecated in favor of videoGetColorRGB and SDL_MapRGBA, which enforce a 184 | * common representation of color values across color tables and hexadecimal 185 | * formats. 186 | */ 187 | Uint32 188 | videoGetColorHex(lua_State *L, int index) 189 | { 190 | SDL_Color c = videoGetColorRGB(L, index); 191 | 192 | return c.a << 24 | c.r << 16 | c.g << 8 | c.b; 193 | } 194 | 195 | SDL_Color 196 | videoGetColorRGB(lua_State *L, int index) 197 | { 198 | SDL_Color c = { 0, 0, 0, 0 }; 199 | 200 | if (lua_type(L, index) == LUA_TNUMBER) { 201 | int value = lua_tointeger(L, index); 202 | 203 | c.a = ((value >> 24) & 0xFF); 204 | c.r = ((value >> 16) & 0xFF); 205 | c.g = ((value >> 8) & 0xFF); 206 | c.b = ((value) & 0xFF); 207 | } else if (lua_type(L, index) == LUA_TTABLE) { 208 | c.r = tableGetInt(L, index, "r"); 209 | c.g = tableGetInt(L, index, "g"); 210 | c.b = tableGetInt(L, index, "b"); 211 | c.a = tableGetInt(L, index, "a"); 212 | } 213 | 214 | return c; 215 | } 216 | 217 | int 218 | videoGetColorsRGB(lua_State *L, int index, Array *colors) 219 | { 220 | return readTable(L, index, colors, sizeof (SDL_Color), readColors); 221 | } 222 | 223 | void 224 | videoPushColorHex(lua_State *L, const SDL_Color *c) 225 | { 226 | lua_pushinteger(L, (c->a << 24) | (c->r << 16) | (c->g << 8) | c->b); 227 | } 228 | 229 | void 230 | videoPushColorRGB(lua_State *L, const SDL_Color *color) 231 | { 232 | lua_createtable(L, 0, 4); 233 | 234 | tableSetInt(L, -1, "r", color->r); 235 | tableSetInt(L, -1, "g", color->g); 236 | tableSetInt(L, -1, "b", color->b); 237 | tableSetInt(L, -1, "a", color->a); 238 | } 239 | 240 | void 241 | videoGetDisplayMode(lua_State *L, int idx, SDL_DisplayMode *mode) 242 | { 243 | luaL_checktype(L, idx, LUA_TTABLE); 244 | 245 | mode->format = tableGetInt(L, idx, "format"); 246 | mode->w = tableGetInt(L, idx, "w"); 247 | mode->h = tableGetInt(L, idx, "h"); 248 | mode->refresh_rate = tableGetInt(L, idx, "refreshRate"); 249 | mode->driverdata = NULL; 250 | } 251 | 252 | void 253 | videoPushDisplayMode(lua_State *L, const SDL_DisplayMode *mode) 254 | { 255 | lua_createtable(L, 4, 4); 256 | 257 | tableSetInt(L, -1, "w", mode->w); 258 | tableSetInt(L, -1, "h", mode->h); 259 | tableSetInt(L, -1, "format", mode->format); 260 | tableSetInt(L, -1, "refreshRate", mode->refresh_rate); 261 | } 262 | -------------------------------------------------------------------------------- /common/video.h: -------------------------------------------------------------------------------- 1 | /* 2 | * video.h -- video initialization and display management 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _VIDEO_H_ 20 | #define _VIDEO_H_ 21 | 22 | #include 23 | #include 24 | 25 | /* -------------------------------------------------------- 26 | * Shared functions 27 | * -------------------------------------------------------- */ 28 | 29 | /** 30 | * @struct line 31 | * @brief Get line coordinates 32 | */ 33 | typedef struct line { 34 | int x1; 35 | int y1; 36 | int x2; 37 | int y2; 38 | } Line; 39 | 40 | /** 41 | * Push a SDL_Rect as a table to Lua. 42 | * 43 | * @param L the Lua state 44 | * @param rect the rectangle to push 45 | */ 46 | void 47 | videoPushRect(lua_State *L, const SDL_Rect *rect); 48 | 49 | /** 50 | * Get a SDL_Rect from a Lua table. If the value at index is not a 51 | * table, raises an error. 52 | * 53 | * @param L the Lua state 54 | * @param index the table index 55 | * @param rect the result 56 | */ 57 | void 58 | videoGetRect(lua_State *L, int index, SDL_Rect *rect); 59 | 60 | /** 61 | * Get a list of rects from table of tables. Does not raises an error. 62 | * 63 | * @param L the Lua state 64 | * @param index the table index 65 | * @param array the array to fill (will be initialized) 66 | * @return 0 on success or -1 on failure 67 | */ 68 | int 69 | videoGetRects(lua_State *L, int index, Array *rects); 70 | 71 | /** 72 | * Push a SDL_Point as a table to Lua. 73 | * 74 | * @param L the Lua state 75 | * @param point the point to push 76 | */ 77 | void 78 | videoPushPoint(lua_State *L, const SDL_Point *point); 79 | 80 | /** 81 | * Get a point from a Lua table. If the value at index is not a 82 | * table, raises an error. 83 | * 84 | * @param L the Lua state 85 | * @param index the table index 86 | * @param point the result 87 | */ 88 | void 89 | videoGetPoint(lua_State *L, int index, SDL_Point *point); 90 | 91 | /** 92 | * Get a list of points from table of tables. Does not raises an error. 93 | * 94 | * @param L the Lua state 95 | * @param index the table index 96 | * @param array the array to fill (will be initialized) 97 | * @return 0 on success or -1 on failure 98 | */ 99 | int 100 | videoGetPoints(lua_State *L, int index, Array *array); 101 | 102 | /** 103 | * Get a line as 4 int or a table of 4 fields. 104 | * 105 | * @param L the Lua state 106 | * @param index the index 107 | * @param line the line coords 108 | */ 109 | void 110 | videoGetLine(lua_State *L, int index, Line *line); 111 | 112 | /** 113 | * Get a color from a Lua table or a hexadecimal number. 114 | * 115 | * NOTE: This method is deprecated in favor of videoGetColorRGB + SDL_MapRGBA. 116 | * 117 | * @param L the Lua state 118 | * @param index the value index 119 | * @return the color as hexadecimal 120 | */ 121 | Uint32 122 | videoGetColorHex(lua_State *L, int index); 123 | 124 | /** 125 | * Get a color from a Lua table or a hexadecimal number. 126 | * 127 | * @param L the Lua state 128 | * @param index the value index 129 | * @return the color as RGB structure 130 | */ 131 | SDL_Color 132 | videoGetColorRGB(lua_State *L, int index); 133 | 134 | /** 135 | * Read colors from Lua and sets them to the colors array as SDL_Color 136 | * structure. 137 | * 138 | * @param L the Lua state 139 | * @param index the colors index 140 | * @param colors the sequence of colors 141 | */ 142 | int 143 | videoGetColorsRGB(lua_State *L, int index, Array *colors); 144 | 145 | /** 146 | * Push a SDL_Color as a table with three fields r, g, b to Lua. 147 | * 148 | * @param L the Lua state 149 | * @param color the color 150 | */ 151 | void 152 | videoPushColorRGB(lua_State *L, const SDL_Color *color); 153 | 154 | /** 155 | * Push a SDL_Color as a hexadecimal integer in ARGB8888 format to Lua. 156 | * 157 | * @param L the Lua state 158 | * @param color the color 159 | */ 160 | void 161 | videoPushColorHex(lua_State *L, const SDL_Color *color); 162 | 163 | /** 164 | * Get a SDL_DisplayMode from a Lua table. Raises an error if 165 | * idx is not a table. 166 | * 167 | * @param L the Lua state 168 | * @param idx the value index 169 | * @param mode the destination vaule 170 | */ 171 | void 172 | videoGetDisplayMode(lua_State *L, int idx, SDL_DisplayMode *mode); 173 | 174 | /** 175 | * Push a SDL_DisplayMode as a table. 176 | * 177 | * @param L the Lua state 178 | * @param mode the mode 179 | */ 180 | void 181 | videoPushDisplayMode(lua_State *L, const SDL_DisplayMode *mode); 182 | 183 | #endif /* !_VIDEO_H_ */ 184 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # CMakeLists.txt -- build system for LuaSDL2 3 | # 4 | # Copyright (c) 2013, 2014 David Demelier 5 | # 6 | # Permission to use, copy, modify, and/or distribute this software for any 7 | # purpose with or without fee is hereby granted, provided that the above 8 | # copyright notice and this permission notice appear in all copies. 9 | # 10 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | # 18 | 19 | project(examples C) 20 | 21 | # Option to enable / disable examples installation 22 | option(WITH_DOCS "Installation of documentation and examples" On) 23 | 24 | set( 25 | DIRECTORIES 26 | audio 27 | font 28 | image 29 | joystick 30 | keyboard 31 | paths 32 | rwops 33 | tcp 34 | threads 35 | udp 36 | ) 37 | 38 | if (WITH_DOCS) 39 | install( 40 | DIRECTORY ${DIRECTORIES} 41 | DESTINATION ${WITH_DOCSDIR}/examples 42 | ) 43 | endif () 44 | -------------------------------------------------------------------------------- /examples/audio/audio-processor.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- audio-processor.lua -- the callback function 3 | -- 4 | 5 | local SDL = require "SDL" 6 | 7 | local args = { ... } 8 | 9 | local sound = { } 10 | local channel = SDL.getChannel "Audio" 11 | 12 | -- 13 | -- This will be called. 14 | -- 15 | sound.data = channel:first() 16 | sound.buf = sound.data.data 17 | sound.pos = 0 18 | sound.len = sound.data.length 19 | 20 | if not sound.data then 21 | error("No data to play") 22 | end 23 | 24 | return function (length) 25 | if length == 0 then 26 | return nil 27 | end 28 | 29 | if length > sound.len then 30 | length = sound.len 31 | end 32 | 33 | local s = sound.buf:sub(sound.pos + 1, sound.pos + 1 + length) 34 | 35 | sound.pos = sound.pos + length 36 | sound.len = sound.len - length 37 | 38 | if #s == 0 then 39 | return nil 40 | end 41 | 42 | return s 43 | end 44 | -------------------------------------------------------------------------------- /examples/audio/audio.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- audio.lua -- testing the SDL audio API 3 | -- 4 | 5 | local SDL = require "SDL" 6 | 7 | -- Init SDL 8 | SDL.init { 9 | SDL.flags.Audio 10 | } 11 | 12 | -- Channel for data and the callback 13 | local channel = SDL.getChannel "Audio" 14 | 15 | -- Prepare the audio spec we want 16 | local spec = { 17 | callback = "audio-processor.lua", 18 | allowchanges = true, 19 | frequency = 44100, 20 | format = SDL.audioFormat.S16, 21 | samples = 1024, 22 | channels = 2 23 | } 24 | 25 | local wav, err = SDL.loadWAV("gun.wav") 26 | if not wav then 27 | error(err) 28 | end 29 | 30 | -- Pass the wav file to the audio-processor 31 | channel:push(wav) 32 | 33 | local dev, err = SDL.openAudioDevice(spec) 34 | if not dev then 35 | error(err) 36 | end 37 | 38 | dev:pause(false) 39 | SDL.delay(5000) 40 | -------------------------------------------------------------------------------- /examples/audio/gun.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/examples/audio/gun.wav -------------------------------------------------------------------------------- /examples/font/DejaVuSans.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/examples/font/DejaVuSans.ttf -------------------------------------------------------------------------------- /examples/font/font.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- font.lua -- show SDL_ttf module with UTF-8 string 3 | -- 4 | 5 | local SDL = require "SDL" 6 | local font = require "SDL.ttf" 7 | 8 | local ret, err = SDL.init { SDL.flags.Video } 9 | if not ret then 10 | error(err) 11 | end 12 | 13 | local ret, err = font.init() 14 | if not ret then 15 | error(err) 16 | end 17 | 18 | local win, err = SDL.createWindow { 19 | title = "Image", 20 | height = 100, 21 | width = 100 22 | } 23 | 24 | if not win then 25 | error(err) 26 | end 27 | 28 | local rdr, err = SDL.createRenderer(win, 0, 0) 29 | if not rdr then 30 | error(err) 31 | end 32 | 33 | local f, err = font.open("DejaVuSans.ttf", 10) 34 | if not f then 35 | error(err) 36 | end 37 | 38 | local s, err = f:renderUtf8("Gérard!", "blended", { r = 255, g = 255, b = 255 }) 39 | if not s then 40 | error(err) 41 | end 42 | 43 | local t = rdr:createTextureFromSurface(s) 44 | if not t then 45 | error(err) 46 | end 47 | 48 | rdr:clear() 49 | rdr:copy(t) 50 | rdr:present() 51 | 52 | SDL.delay(2000) -------------------------------------------------------------------------------- /examples/image/Lua-SDL2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/examples/image/Lua-SDL2.png -------------------------------------------------------------------------------- /examples/image/image.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- image.lua -- shows SDL_image module for Lua 3 | -- 4 | 5 | local SDL = require "SDL" 6 | local image = require "SDL.image" 7 | 8 | local ret, err = SDL.init { SDL.flags.Video } 9 | if not ret then 10 | error(err) 11 | end 12 | 13 | local formats, ret, err = image.init { image.flags.PNG } 14 | if not ret then 15 | error(err) 16 | end 17 | 18 | local win, err = SDL.createWindow { 19 | title = "Image", 20 | height = 256, 21 | width = 256 22 | } 23 | 24 | if not win then 25 | error(err) 26 | end 27 | 28 | local rdr, err = SDL.createRenderer(win, 0, 0) 29 | if not rdr then 30 | error(err) 31 | end 32 | 33 | local img, err = image.load("Lua-SDL2.png") 34 | if not img then 35 | error(err) 36 | end 37 | 38 | img = rdr:createTextureFromSurface(img) 39 | 40 | for i = 1, 50 do 41 | rdr:setDrawColor(0xFFFFFF) 42 | rdr:clear() 43 | rdr:copy(img) 44 | rdr:present() 45 | 46 | SDL.delay(100) 47 | end 48 | -------------------------------------------------------------------------------- /examples/joystick/joystick.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- joystick.lua -- joystick management 3 | -- 4 | 5 | local SDL = require "SDL" 6 | 7 | local ret, err = SDL.init { SDL.flags.Joystick } 8 | if not ret then 9 | error(err) 10 | end 11 | 12 | -- Try to open the first joystick 13 | local joy, err = SDL.joystickOpen(0) 14 | if not joy then 15 | error(err) 16 | end 17 | 18 | print(string.format("Joystick 0: %s", joy:name())) 19 | print(string.format(" buttons: %d", joy:numButtons())) 20 | print(string.format(" hats: %d", joy:numHats())) 21 | print(string.format(" axes: %d", joy:numAxes())) 22 | print(string.format(" balls: %d", joy:numBalls())) 23 | 24 | while true do 25 | for e in SDL.pollEvent() do 26 | if e.type == SDL.event.Quit then 27 | break 28 | elseif e.type == SDL.event.JoyAxisMotion then 29 | print(string.format("axis %d: %d", e.axis, e.value)) 30 | elseif e.type == SDL.event.JoyBallMotion then 31 | print(string.format("ball motion %d: %d, %d", e.ball, e.xrel, e.yrel)) 32 | elseif e.type == SDL.event.JoyButtonDown then 33 | print(string.format("button down: %d", e.button)) 34 | elseif e.type == SDL.event.JoyButtonUp then 35 | print(string.format("button up: %d", e.button)) 36 | end 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /examples/keyboard/keyboard.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- keyboard.lua -- process keyboard states 3 | -- 4 | 5 | local SDL = require "SDL" 6 | 7 | SDL.init { 8 | SDL.flags.Video 9 | } 10 | 11 | SDL.createWindow { 12 | title = "Keyboard", 13 | width = 50, 14 | height = 50 15 | } 16 | 17 | local keys = SDL.getKeyboardState() 18 | 19 | while true do 20 | SDL.pumpEvents() 21 | 22 | if keys[SDL.scancode.Return] then 23 | print("Return pressed") 24 | end 25 | if keys[SDL.scancode.Escape] then 26 | print("Exiting!") 27 | break 28 | end 29 | 30 | SDL.delay(1000) 31 | end 32 | -------------------------------------------------------------------------------- /examples/paths/paths.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- paths.lua -- show standard directories 3 | -- 4 | 5 | local SDL = require "SDL" 6 | 7 | print(string.format("Base directory: %s", SDL.getBasePath())) 8 | print(string.format("Preference directory: %s", SDL.getPrefPath("Lua-SDL2", "Testing"))) 9 | -------------------------------------------------------------------------------- /examples/rwops/rwops.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- rwops.lua -- write a file with RWOps 3 | -- 4 | 5 | local SDL = require "SDL" 6 | 7 | SDL.init { SDL.flags.Video } 8 | 9 | local writer = { 10 | file = io.open("test.bin", "wb") 11 | } 12 | 13 | if not writer.file then 14 | error("Unable to open file") 15 | end 16 | 17 | function writer.size() 18 | return -1 19 | end 20 | 21 | function writer.close() 22 | writer.file:close() 23 | end 24 | 25 | function writer.seek(offset, whence) 26 | return 0 27 | end 28 | 29 | function writer.read(n, size) 30 | end 31 | 32 | function writer.write(data, n, size) 33 | writer.file:write(data) 34 | end 35 | 36 | local rw, err = SDL.RWCreate(writer) 37 | if not rw then 38 | error(err) 39 | end 40 | 41 | rw:writeByte(1, 16, "LE") 42 | -------------------------------------------------------------------------------- /examples/tcp/client.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- client.lua -- send "Hello" to a server using SDL_net 3 | -- 4 | 5 | local net = require "SDL.net" 6 | 7 | -- Init net 8 | net.init() 9 | 10 | -- Create and connect 11 | local addr = net.resolveHost("localhost", 5959) 12 | local s = net.openTcp(addr) 13 | 14 | s:send("Hello") 15 | net.quit() 16 | -------------------------------------------------------------------------------- /examples/tcp/server.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- server.lua -- echo server using SDL_net 3 | -- 4 | 5 | local net = require "SDL.net" 6 | 7 | -- Init net 8 | net.init() 9 | 10 | -- Bind a socket 11 | local addr = net.resolveHost(nil, 5959) 12 | local s = net.openTcp(addr) 13 | 14 | -- Create a set 15 | local set = net.set(32) 16 | 17 | -- Add the socket for accepting clients 18 | set:add(s) 19 | 20 | -- Store all clients too 21 | local clients = { } 22 | 23 | while true do 24 | local n = set:checkSockets(-1) 25 | 26 | if n > 0 then 27 | if s:ready() then 28 | local c = s:accept() 29 | if c then 30 | print("New client") 31 | table.insert(clients, c) 32 | set:add(c) 33 | end 34 | else 35 | for i, c in ipairs(clients) do 36 | if c:ready() then 37 | local value, n = c:recv(128) 38 | 39 | if not value then 40 | print("Client disconnected") 41 | set:del(c) 42 | table.remove(clients, i) 43 | else 44 | print(value) 45 | end 46 | end 47 | end 48 | end 49 | end 50 | end 51 | 52 | -- Close everything 53 | net.quit() 54 | -------------------------------------------------------------------------------- /examples/threads/channel.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- channel.lua -- shows how to pass / wait data between channels 3 | -- 4 | 5 | local SDL = require "SDL" 6 | 7 | SDL.init { SDL.flags.Video } 8 | 9 | local t, err = SDL.createThread("test", 10 | function () 11 | local SDL = require "SDL" 12 | 13 | local channel = SDL.getChannel "Test" 14 | 15 | print("Waiting...") 16 | local v = channel:wait() 17 | print("Received: " .. tostring(v)) 18 | 19 | return 0 20 | end 21 | ) 22 | 23 | if not t then 24 | error(err) 25 | end 26 | 27 | SDL.delay(1000) 28 | 29 | 30 | print("Main...") 31 | SDL.delay(3000) 32 | 33 | local channel = SDL.getChannel "Test" 34 | 35 | print("Pushing...") 36 | channel:supply(true) 37 | print("He received") 38 | -------------------------------------------------------------------------------- /examples/udp/client.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- client.lua -- UDP client 3 | -- 4 | 5 | local net = require "SDL.net" 6 | 7 | -- Init 8 | net.init() 9 | 10 | -- "connect" to host and send hello 11 | local addr = net.resolveHost("localhost", 9898) 12 | local s = net.openUdp(0) 13 | 14 | -- Send "Hello" 15 | local ret, err = s:send("Hello", addr) 16 | -------------------------------------------------------------------------------- /examples/udp/server.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- server.lua -- UDP server 3 | -- 4 | 5 | local net = require "SDL.net" 6 | 7 | -- Init 8 | net.init() 9 | 10 | -- Create a server socket 11 | local s = net.openUdp(9898) 12 | 13 | while true do 14 | local v, num = s:recv(32) 15 | 16 | if v then 17 | print(v) 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /lua-sdl2-scm-3.rockspec: -------------------------------------------------------------------------------- 1 | package = "Lua-SDL2" 2 | version = "scm-3" 3 | source = { 4 | url = "https://github.com/Tangent128/luasdl2/archive/v2.0.3-3.tar.gz", 5 | md5 = "", 6 | dir = "luasdl2-2.0.3-3" 7 | } 8 | source = { 9 | -- when making a release rockspec, update fields in the above source 10 | -- block and delete this source block. 11 | url = "git://github.com/Tangent128/luasdl2" 12 | } 13 | description = { 14 | summary = "Lua-SDL2 is a pure C binding of SDL 2.0 for Lua 5.1, JIT, 5.2, 5.3 and 5.4", 15 | detailed = "Lua-SDL2 is a pure C binding of SDL 2.0 for Lua 5.1, JIT, 5.2, 5.3 and 5.4", 16 | homepage = "https://github.com/Tangent128/luasdl2/", 17 | license = "ISC", 18 | maintainer = "Joseph Wallace " 19 | } 20 | dependencies = {} 21 | external_dependencies = { 22 | SDL2 = { 23 | header = "SDL2/SDL_scancode.h" 24 | }, 25 | SDL2_image = { 26 | header = "SDL2/SDL_image.h" 27 | }, 28 | SDL2_mixer = { 29 | header = "SDL2/SDL_mixer.h" 30 | }, 31 | SDL2_net = { 32 | header = "SDL2/SDL_net.h" 33 | }, 34 | SDL2_ttf = { 35 | header = "SDL2/SDL_ttf.h" 36 | }, 37 | 38 | platforms = { 39 | windows = { 40 | SDL2 = { 41 | header = "SDL_scancode.h" 42 | }, 43 | SDL2_image = { 44 | header = "SDL_image.h" 45 | }, 46 | SDL2_mixer = { 47 | header = "SDL_mixer.h" 48 | }, 49 | SDL2_net = { 50 | header = "SDL_net.h" 51 | }, 52 | SDL2_ttf = { 53 | header = "SDL_ttf.h" 54 | }, 55 | } 56 | } 57 | } 58 | 59 | local function PlusCommon(...) 60 | return { 61 | "common/array.c", 62 | "common/common.c", 63 | "common/rwops.c", 64 | "common/surface.c", 65 | "common/table.c", 66 | "common/variant.c", 67 | "common/video.c", 68 | ... 69 | } 70 | end 71 | 72 | build = { 73 | type = "builtin", 74 | modules = { 75 | SDL = { 76 | libraries = {"SDL2"}, 77 | defines = {}, 78 | incdirs = {"$(SDL2_INCDIR)/SDL2", "src/", "extern/queue/", "./", "rocks/"}, 79 | libdirs = {"$(SDL2_LIBDIR)"}, 80 | sources = PlusCommon( 81 | "src/audio.c", 82 | "src/channel.c", 83 | "src/clipboard.c", 84 | "src/cpu.c", 85 | "src/display.c", 86 | "src/events.c", 87 | "src/filesystem.c", 88 | "src/gamecontroller.c", 89 | "src/gl.c", 90 | "src/haptic.c", 91 | "src/joystick.c", 92 | "src/keyboard.c", 93 | "src/logging.c", 94 | "src/mouse.c", 95 | "src/platform.c", 96 | "src/power.c", 97 | "src/rectangle.c", 98 | "src/renderer.c", 99 | "src/SDL.c", 100 | "src/texture.c", 101 | "src/thread.c", 102 | "src/timer.c", 103 | "src/window.c", 104 | "src/vulkan.c" 105 | ), 106 | }, 107 | ["SDL.image"] = { 108 | libraries = {"SDL2", "SDL2_image"}, 109 | defines = {}, 110 | incdirs = {"$(SDL2_INCDIR)/SDL2", "src/", "extern/queue/", "./", "rocks/"}, 111 | libdirs = {"$(SDL2_LIBDIR)"}, 112 | sources = PlusCommon( 113 | "sdl-image/src/image.c" 114 | ), 115 | }, 116 | ["SDL.mixer"] = { 117 | libraries = {"SDL2", "SDL2_mixer"}, 118 | defines = {}, 119 | incdirs = {"$(SDL2_INCDIR)/SDL2", "src/", "extern/queue/", "./", "rocks/"}, 120 | libdirs = {"$(SDL2_LIBDIR)"}, 121 | sources = PlusCommon( 122 | "sdl-mixer/src/mixer.c" 123 | ), 124 | }, 125 | ["SDL.net"] = { 126 | libraries = {"SDL2", "SDL2_net"}, 127 | defines = {}, 128 | incdirs = {"$(SDL2_INCDIR)/SDL2", "src/", "extern/queue/", "./", "rocks/"}, 129 | libdirs = {"$(SDL2_LIBDIR)"}, 130 | sources = PlusCommon( 131 | "sdl-net/src/net.c" 132 | ), 133 | }, 134 | ["SDL.ttf"] = { 135 | libraries = {"SDL2", "SDL2_ttf"}, 136 | defines = {}, 137 | incdirs = {"$(SDL2_INCDIR)/SDL2", "src/", "extern/queue/", "./", "rocks/"}, 138 | libdirs = {"$(SDL2_LIBDIR)"}, 139 | sources = PlusCommon( 140 | "sdl-ttf/src/ttf.c" 141 | ), 142 | }, 143 | }, 144 | platforms = { 145 | windows = { 146 | modules = { 147 | SDL = { 148 | incdirs = {"$(SDL2_INCDIR)", "src/", "extern/queue/", "./", "rocks/"} 149 | }, 150 | ["SDL.image"] = { 151 | incdirs = {"$(SDL2_INCDIR)", "src/", "extern/queue/", "./", "rocks/"} 152 | }, 153 | ["SDL.mixer"] = { 154 | incdirs = {"$(SDL2_INCDIR)", "src/", "extern/queue/", "./", "rocks/"} 155 | }, 156 | ["SDL.net"] = { 157 | incdirs = {"$(SDL2_INCDIR)", "src/", "extern/queue/", "./", "rocks/"} 158 | }, 159 | ["SDL.ttf"] = { 160 | incdirs = {"$(SDL2_INCDIR)", "src/", "extern/queue/", "./", "rocks/"} 161 | }, 162 | } 163 | } 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /rocks/config.h: -------------------------------------------------------------------------------- 1 | #ifndef _CONFIG_H_ 2 | #define _CONFIG_H_ 3 | 4 | #define VERSION_BINDING_MAJOR 2 5 | #define VERSION_BINDING_MINOR 1 6 | 7 | #endif /* !_CONFIG_H_ */ 8 | -------------------------------------------------------------------------------- /sdl-image/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # CMakeLists.txt -- build system for LuaSDL2 (SDL_image module) 3 | # 4 | # Copyright (c) 2013, 2014 David Demelier 5 | # Copyright (c) 2014 Joseph Wallace 6 | # 7 | # Permission to use, copy, modify, and/or distribute this software for any 8 | # purpose with or without fee is hereby granted, provided that the above 9 | # copyright notice and this permission notice appear in all copies. 10 | # 11 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | 19 | set( 20 | IMAGE_SOURCES 21 | src/image.c 22 | ) 23 | 24 | add_library( 25 | image 26 | MODULE 27 | ${IMAGE_SOURCES} 28 | ) 29 | 30 | set_target_properties( 31 | image 32 | PROPERTIES 33 | PREFIX "" 34 | ) 35 | 36 | target_link_libraries( 37 | image 38 | common 39 | SDL2::image 40 | ) 41 | 42 | install( 43 | TARGETS image 44 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/lua/${Lua_VERSION}/SDL 45 | ) 46 | -------------------------------------------------------------------------------- /sdl-image/src/image.c: -------------------------------------------------------------------------------- 1 | /* 2 | * image.c -- main SDL_image (2.0) module 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | typedef SDL_Surface * (*LoadFunction)(SDL_RWops *); 28 | typedef int (*TypeFunction)(SDL_RWops *); 29 | 30 | /* 31 | * Image.flags 32 | */ 33 | static const CommonEnum ImageFlags[] = { 34 | { "JPG", IMG_INIT_JPG }, 35 | { "PNG", IMG_INIT_PNG }, 36 | { "TIF", IMG_INIT_TIF, }, 37 | { NULL, -1 } 38 | }; 39 | 40 | static const struct ImgInfo { 41 | const char *name; 42 | LoadFunction load; 43 | TypeFunction type; 44 | } loaders[] = { 45 | { "CUR", IMG_LoadCUR_RW, IMG_isCUR }, 46 | { "ICO", IMG_LoadICO_RW, IMG_isICO }, 47 | { "BMP", IMG_LoadBMP_RW, IMG_isBMP }, 48 | { "PNM", IMG_LoadPNM_RW, IMG_isPNM }, 49 | { "XPM", IMG_LoadXPM_RW, IMG_isXPM }, 50 | { "XCF", IMG_LoadXCF_RW, IMG_isXCF }, 51 | { "PCX", IMG_LoadPCX_RW, IMG_isPCX }, 52 | { "GIF", IMG_LoadGIF_RW, IMG_isGIF }, 53 | { "JPG", IMG_LoadJPG_RW, IMG_isJPG }, 54 | { "TIF", IMG_LoadTIF_RW, IMG_isTIF }, 55 | { "PNG", IMG_LoadPNG_RW, IMG_isPNG }, 56 | { "TGA", IMG_LoadTGA_RW, NULL /* WHY? */ }, 57 | { "LBM", IMG_LoadLBM_RW, IMG_isLBM }, 58 | { "XV", IMG_LoadXV_RW, IMG_isXV }, 59 | { NULL, NULL, NULL } 60 | }; 61 | 62 | /* 63 | * Image.init(flags) 64 | * 65 | * Arguments: 66 | * flags the formats requested 67 | * 68 | * Returns: 69 | * The initialized formats 70 | * Nil if some have not been supported 71 | * The error message 72 | */ 73 | static int 74 | l_image_init(lua_State *L) 75 | { 76 | int flags = commonGetEnum(L, 1); 77 | int ret; 78 | 79 | ret = IMG_Init(flags); 80 | commonPushEnum(L, ret, ImageFlags); 81 | 82 | if ((ret & flags) != flags) 83 | return commonPush(L, "n s", IMG_GetError()) + 1; 84 | 85 | return commonPush(L, "b", 1) + 1; 86 | } 87 | 88 | /* 89 | * Image.quit() 90 | */ 91 | static int 92 | l_image_quit(lua_State *L) 93 | { 94 | IMG_Quit(); 95 | 96 | (void)L; 97 | 98 | return 0; 99 | } 100 | 101 | /* 102 | * Image.load(path) 103 | * 104 | * Arguments: 105 | * path the path to the image 106 | * 107 | * Returns: 108 | * The surface or nil on failure 109 | * The error message 110 | */ 111 | static int 112 | l_image_load(lua_State *L) 113 | { 114 | const char *path = luaL_checkstring(L, 1); 115 | SDL_Surface *surf; 116 | 117 | surf = IMG_Load(path); 118 | if (surf == NULL) 119 | return commonPushSDLError(L, 1); 120 | 121 | return commonPush(L, "p", SurfaceName, surf); 122 | } 123 | 124 | /* 125 | * Image.load_RW(rwops, name) 126 | * 127 | * Arguments: 128 | * rwops the RWops 129 | * name (optional) the type name 130 | * 131 | * Returns: 132 | * The surface or nil 133 | * The error message 134 | */ 135 | static int 136 | l_image_load_RW(lua_State *L) 137 | { 138 | SDL_RWops *ops = commonGetAs(L, 1, RWOpsName, SDL_RWops *); 139 | SDL_Surface *surf; 140 | 141 | /* If name is specified we use a specific function */ 142 | if (lua_gettop(L) >= 2) { 143 | const char *name = luaL_checkstring(L, 2); 144 | const struct ImgInfo *info; 145 | 146 | for (info = loaders; info->name != NULL; ++info) { 147 | if (strcmp(info->name, name) == 0) { 148 | surf = info->load(ops); 149 | break; 150 | } 151 | } 152 | 153 | /* Reached mean bad type requested */ 154 | return luaL_error(L, "invalid image type %s", name); 155 | } else { 156 | surf = IMG_Load_RW(ops, 0); 157 | } 158 | 159 | if (surf == NULL) 160 | return commonPushSDLError(L, 1); 161 | 162 | return commonPush(L, "p", SurfaceName, surf); 163 | } 164 | 165 | /* 166 | * Image.is(rwops, type) 167 | * 168 | * Arguments: 169 | * rwops the RWops 170 | * type the type 171 | * 172 | * Returns: 173 | * True if the file is one requested or nil on failure 174 | * The error message 175 | */ 176 | static int 177 | l_image_is(lua_State *L) 178 | { 179 | SDL_RWops *ops = commonGetAs(L, 1, RWOpsName, SDL_RWops *); 180 | const char *name = luaL_checkstring(L, 2); 181 | const struct ImgInfo *info; 182 | 183 | for (info = loaders; info->name != NULL; ++info) 184 | if (strcmp(info->name, name) == 0 && info->type != NULL) 185 | return commonPush(L, "b", info->type(ops)); 186 | 187 | return commonPush(L, "ns", "invalid type given"); 188 | } 189 | 190 | static const luaL_Reg ImageFunctions[] = { 191 | { "init", l_image_init }, 192 | { "quit", l_image_quit }, 193 | { "load", l_image_load }, 194 | { "load_RW", l_image_load_RW }, 195 | { "is", l_image_is }, 196 | { NULL, NULL } 197 | }; 198 | 199 | int EXPORT 200 | luaopen_SDL_image(lua_State *L) 201 | { 202 | /* New SDL.image library */ 203 | commonNewLibrary(L, ImageFunctions); 204 | 205 | /* Flags for IMG_Init() */ 206 | commonBindEnum(L, -1, "flags", ImageFlags); 207 | 208 | return 1; 209 | } 210 | -------------------------------------------------------------------------------- /sdl-mixer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # CMakeLists.txt -- build system for LuaSDL2 (SDL_mixer module) 3 | # 4 | # Copyright (c) 2013, 2014 David Demelier 5 | # Copyright (c) 2014 Joseph Wallace 6 | # 7 | # Permission to use, copy, modify, and/or distribute this software for any 8 | # purpose with or without fee is hereby granted, provided that the above 9 | # copyright notice and this permission notice appear in all copies. 10 | # 11 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | 19 | set( 20 | MIXER_SOURCES 21 | src/mixer.c 22 | ) 23 | 24 | add_library( 25 | mixer 26 | MODULE 27 | ${MIXER_SOURCES} 28 | ) 29 | 30 | set_target_properties( 31 | mixer 32 | PROPERTIES 33 | PREFIX "" 34 | ) 35 | 36 | target_link_libraries( 37 | mixer 38 | common 39 | SDL2::mixer 40 | ) 41 | 42 | install( 43 | TARGETS mixer 44 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/lua/${Lua_VERSION}/SDL 45 | ) 46 | -------------------------------------------------------------------------------- /sdl-net/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # CMakeLists.txt -- build system for LuaSDL2 (SDL_net module) 3 | # 4 | # Copyright (c) 2013, 2014 David Demelier 5 | # Copyright (c) 2014 Joseph Wallace 6 | # 7 | # Permission to use, copy, modify, and/or distribute this software for any 8 | # purpose with or without fee is hereby granted, provided that the above 9 | # copyright notice and this permission notice appear in all copies. 10 | # 11 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | 19 | set( 20 | NET_SOURCES 21 | src/net.c 22 | ) 23 | 24 | add_library( 25 | net 26 | MODULE 27 | ${NET_SOURCES} 28 | ) 29 | 30 | set_target_properties( 31 | net 32 | PROPERTIES 33 | PREFIX "" 34 | ) 35 | 36 | target_link_libraries( 37 | net 38 | common 39 | SDL2::net 40 | ) 41 | 42 | install( 43 | TARGETS net 44 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/lua/${Lua_VERSION}/SDL 45 | ) 46 | -------------------------------------------------------------------------------- /sdl-ttf/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # CMakeLists.txt -- build system for LuaSDL2 (SDL_ttf module) 3 | # 4 | # Copyright (c) 2013, 2014 David Demelier 5 | # Copyright (c) 2014 Joseph Wallace 6 | # 7 | # Permission to use, copy, modify, and/or distribute this software for any 8 | # purpose with or without fee is hereby granted, provided that the above 9 | # copyright notice and this permission notice appear in all copies. 10 | # 11 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | 19 | set( 20 | TTF_SOURCES 21 | src/ttf.c 22 | ) 23 | 24 | add_library( 25 | ttf 26 | MODULE 27 | ${TTF_SOURCES} 28 | ) 29 | 30 | set_target_properties( 31 | ttf 32 | PROPERTIES 33 | PREFIX "" 34 | ) 35 | 36 | target_link_libraries( 37 | ttf 38 | common 39 | SDL2::ttf 40 | ) 41 | 42 | install( 43 | TARGETS ttf 44 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/lua/${Lua_VERSION}/SDL 45 | ) 46 | -------------------------------------------------------------------------------- /src/audio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * audio.h -- audio playback and recording 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _AUDIO_H_ 20 | #define _AUDIO_H_ 21 | 22 | #include 23 | 24 | #define AudioDeviceName AudioObject.name 25 | 26 | extern const luaL_Reg AudioFunctions[]; 27 | 28 | extern const CommonEnum AudioFormat[]; 29 | 30 | extern const CommonEnum AudioStatus[]; 31 | 32 | extern const CommonObject AudioObject; 33 | 34 | #endif /* !_AUDIO_H_ */ 35 | -------------------------------------------------------------------------------- /src/channel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * channel.h -- channel management (thread communication) 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #define ChannelName ChannelObject.name 22 | 23 | extern const luaL_Reg ChannelFunctions[]; 24 | 25 | extern const CommonObject ChannelObject; 26 | 27 | extern SDL_mutex *ChannelMutex; 28 | -------------------------------------------------------------------------------- /src/clipboard.c: -------------------------------------------------------------------------------- 1 | /* 2 | * clipboard.c -- desktop clipboard manager 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include "clipboard.h" 20 | 21 | /* 22 | * SDL.getClipboardText() 23 | * 24 | * Returns: 25 | * The clipboard text 26 | */ 27 | static int 28 | l_video_getClipboardText(lua_State *L) 29 | { 30 | char *str; 31 | 32 | str = SDL_GetClipboardText(); 33 | lua_pushstring(L, str); 34 | SDL_free(str); 35 | 36 | return 1; 37 | } 38 | 39 | /* 40 | * SDL.hasClipboardText() 41 | * 42 | * Returns: 43 | * True if has clipboard text 44 | */ 45 | static int 46 | l_video_hasClipboardText(lua_State *L) 47 | { 48 | return commonPush(L, "b", SDL_HasClipboardText()); 49 | } 50 | 51 | /* 52 | * SDL.setClipboardText(text) 53 | * 54 | * Arguments: 55 | * text the text 56 | * 57 | * Returns: 58 | * True on success or false 59 | * The error message 60 | */ 61 | static int 62 | l_video_setClipboardText(lua_State *L) 63 | { 64 | const char *text = luaL_checkstring(L, 1); 65 | 66 | if (SDL_SetClipboardText(text) < 0) 67 | return commonPushSDLError(L, 1); 68 | 69 | return commonPush(L, "b", 1); 70 | } 71 | 72 | const luaL_Reg ClipboardFunctions[] = { 73 | { "getClipboardText", l_video_getClipboardText }, 74 | { "hasClipboardText", l_video_hasClipboardText }, 75 | { "setClipboardText", l_video_setClipboardText }, 76 | { NULL, NULL } 77 | }; 78 | -------------------------------------------------------------------------------- /src/clipboard.h: -------------------------------------------------------------------------------- 1 | /* 2 | * clipboard.h -- desktop clipboard manager 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _CLIPBOARD_H_ 20 | #define _CLIPBOARD_H_ 21 | 22 | #include 23 | 24 | extern const luaL_Reg ClipboardFunctions[]; 25 | 26 | #endif /* !_CLIPBOARD_H_ */ 27 | -------------------------------------------------------------------------------- /src/cpu.c: -------------------------------------------------------------------------------- 1 | /* 2 | * cpu.c -- CPU feature detection 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * Copyright (c) 2016 Webster Sheets 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice appear in all copies. 10 | * 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | */ 19 | 20 | #include "cpu.h" 21 | 22 | /* 23 | * SDL.getCPUCacheLineSize() 24 | * 25 | * Returns: 26 | * The value 27 | */ 28 | static int 29 | l_cpu_getCacheLineSize(lua_State *L) 30 | { 31 | return commonPush(L, "i", SDL_GetCPUCacheLineSize()); 32 | 33 | } 34 | 35 | /* 36 | * SDL.getCPUCount() 37 | * 38 | * Returns: 39 | * The number of CPU 40 | */ 41 | static int 42 | l_cpu_getCount(lua_State *L) 43 | { 44 | return commonPush(L, "i", SDL_GetCPUCount()); 45 | } 46 | 47 | /* 48 | * SDL.has3DNow() 49 | * 50 | * Returns: 51 | * True if has 52 | */ 53 | static int 54 | l_cpu_has3DNow(lua_State *L) 55 | { 56 | return commonPush(L, "b", SDL_Has3DNow()); 57 | } 58 | 59 | /* 60 | * SDL.hasAltiVec() 61 | * 62 | * Returns: 63 | * True if has 64 | */ 65 | static int 66 | l_cpu_hasAltiVec(lua_State *L) 67 | { 68 | return commonPush(L, "b", SDL_HasAltiVec()); 69 | } 70 | 71 | #if SDL_VERSION_ATLEAST(2, 0, 2) 72 | /* 73 | * SDL.hasAVX() 74 | * 75 | * Returns: 76 | * True if the CPU has support for AVX 77 | */ 78 | static int 79 | l_cpu_hasAVX(lua_State *L) 80 | { 81 | return commonPush(L, "b", SDL_HasAVX()); 82 | } 83 | #endif 84 | 85 | #if SDL_VERSION_ATLEAST(2, 0, 4) 86 | /* 87 | * SDL.hasAVX2() 88 | * 89 | * Returns: 90 | * True if the CPU has support for AVX2 91 | */ 92 | static int 93 | l_cpu_hasAVX2(lua_State *L) 94 | { 95 | return commonPush(L, "b", SDL_HasAVX2()); 96 | } 97 | #endif 98 | 99 | /* 100 | * SDL.hasMMX() 101 | * 102 | * Returns: 103 | * True if has 104 | */ 105 | static int 106 | l_cpu_hasMMX(lua_State *L) 107 | { 108 | return commonPush(L, "b", SDL_HasMMX()); 109 | } 110 | 111 | /* 112 | * SDL.hasRDTSC() 113 | * 114 | * Returns: 115 | * True if has 116 | */ 117 | static int 118 | l_cpu_hasRDTSC(lua_State *L) 119 | { 120 | return commonPush(L, "b", SDL_HasRDTSC()); 121 | } 122 | 123 | /* 124 | * SDL.hasSSE() 125 | * 126 | * Returns: 127 | * True if has 128 | */ 129 | static int 130 | l_cpu_hasSSE(lua_State *L) 131 | { 132 | return commonPush(L, "b", SDL_HasSSE()); 133 | } 134 | 135 | /* 136 | * SDL.hasSSE2() 137 | * 138 | * Returns: 139 | * True if has 140 | */ 141 | static int 142 | l_cpu_hasSSE2(lua_State *L) 143 | { 144 | return commonPush(L, "b", SDL_HasSSE2()); 145 | } 146 | 147 | /* 148 | * SDL.hasSSE41() 149 | * 150 | * Returns: 151 | * True if has 152 | */ 153 | static int 154 | l_cpu_hasSSE41(lua_State *L) 155 | { 156 | return commonPush(L, "b", SDL_HasSSE41()); 157 | } 158 | 159 | /* 160 | * SDL.hasSSE42() 161 | * 162 | * Returns: 163 | * True if has 164 | */ 165 | static int 166 | l_cpu_hasSSE42(lua_State *L) 167 | { 168 | return commonPush(L, "b", SDL_HasSSE42()); 169 | } 170 | 171 | const luaL_Reg CpuFunctions[] = { 172 | { "getCPUCacheLineSize", l_cpu_getCacheLineSize }, 173 | { "getCPUCount", l_cpu_getCount }, 174 | { "has3DNow", l_cpu_has3DNow }, 175 | { "hasAltiVec", l_cpu_hasAltiVec }, 176 | #if SDL_VERSION_ATLEAST(2, 0, 2) 177 | { "hasAVX", l_cpu_hasAVX }, 178 | #endif 179 | #if SDL_VERSION_ATLEAST(2, 0, 4) 180 | { "hasAVX2", l_cpu_hasAVX2 }, 181 | #endif 182 | { "hasMMX", l_cpu_hasMMX }, 183 | { "hasRDTSC", l_cpu_hasRDTSC }, 184 | { "hasSSE", l_cpu_hasSSE }, 185 | { "hasSSE2", l_cpu_hasSSE2 }, 186 | { "hasSSE41", l_cpu_hasSSE41 }, 187 | { "hasSSE42", l_cpu_hasSSE42 }, 188 | { NULL, NULL } 189 | }; 190 | -------------------------------------------------------------------------------- /src/cpu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cpu.h -- CPU feature detection 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _CPU_H_ 20 | #define _CPU_H_ 21 | 22 | #include 23 | 24 | extern const luaL_Reg CpuFunctions[]; 25 | 26 | #endif /* !_CPU_H_ */ 27 | -------------------------------------------------------------------------------- /src/display.h: -------------------------------------------------------------------------------- 1 | /* 2 | * display.h -- basic display functions 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _DISPLAY_H_ 20 | #define _DISPLAY_H_ 21 | 22 | #include 23 | 24 | extern const luaL_Reg DisplayFunctions[]; 25 | 26 | extern const CommonEnum PixelFormat[]; 27 | 28 | #endif /* !_DISPLAY_H_ */ 29 | -------------------------------------------------------------------------------- /src/events.h: -------------------------------------------------------------------------------- 1 | /* 2 | * events.h -- general event management and enumerations 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _EVENTS_H_ 20 | #define _EVENTS_H_ 21 | 22 | #include 23 | 24 | #define EventFilterName EventFilter.name 25 | 26 | extern const luaL_Reg EventFunctions[]; 27 | 28 | extern const CommonEnum EventAction[]; 29 | 30 | extern const CommonEnum EventType[]; 31 | 32 | extern const CommonEnum EventWindow[]; 33 | 34 | extern const CommonObject EventFilter; 35 | 36 | void 37 | eventPush(lua_State *L, const SDL_Event *ev); 38 | 39 | #endif /* !_EVENTS_H_ */ 40 | -------------------------------------------------------------------------------- /src/filesystem.c: -------------------------------------------------------------------------------- 1 | /* 2 | * filesystem.c -- filesystem functions 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include "filesystem.h" 20 | 21 | /* 22 | * SDL.getBasePath() 23 | * 24 | * Returns: 25 | * The base directory where the application runs or nil on failure 26 | * The error message 27 | */ 28 | static int 29 | l_getBasePath(lua_State *L) 30 | { 31 | char *str = SDL_GetBasePath(); 32 | 33 | if (str == NULL) 34 | return commonPushSDLError(L, 1); 35 | 36 | lua_pushstring(L, str); 37 | SDL_free(str); 38 | 39 | return 1; 40 | } 41 | 42 | /* 43 | * SDL.getPrefPath(organization, application) 44 | * 45 | * Arguments: 46 | * organization the organization name 47 | * application the application name 48 | * 49 | * Returns: 50 | * The directory or nil on failure 51 | * The error message 52 | */ 53 | static int 54 | l_getPrefPath(lua_State *L) 55 | { 56 | const char *organization = luaL_checkstring(L, 1); 57 | const char *application = luaL_checkstring(L, 2); 58 | char *str = SDL_GetPrefPath(organization, application); 59 | 60 | if (str == NULL) 61 | return commonPushSDLError(L, 1); 62 | 63 | lua_pushstring(L, str); 64 | SDL_free(str); 65 | 66 | return 1; 67 | } 68 | 69 | const luaL_Reg FilesystemFunctions[] = { 70 | { "getBasePath", l_getBasePath }, 71 | { "getPrefPath", l_getPrefPath }, 72 | { NULL, NULL } 73 | }; 74 | -------------------------------------------------------------------------------- /src/filesystem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * filesystem.h -- filesystem functions 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _FILESYSTEM_H_ 20 | #define _FILESYSTEM_H_ 21 | 22 | #include 23 | 24 | extern const luaL_Reg FilesystemFunctions[]; 25 | 26 | #endif /* !_FILESYSTEM_H_ */ 27 | -------------------------------------------------------------------------------- /src/gamecontroller.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gamecontroller.h -- game controllers event management 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _GAMECONTROLLER_H_ 20 | #define _GAMECONTROLLER_H_ 21 | 22 | #include 23 | 24 | #define GameCtlName GameCtl.name 25 | 26 | extern const luaL_Reg GamectlFunctions[]; 27 | 28 | extern const CommonObject GameCtl; 29 | 30 | extern const CommonEnum GameCtlAxis[]; 31 | 32 | extern const CommonEnum GameCtlButton[]; 33 | 34 | #endif /* !_GAMECONTROLLER_H_ */ 35 | -------------------------------------------------------------------------------- /src/gl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gl.h -- OpenGL management 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _LUA_SDL_GL_H_ 20 | #define _LUA_SDL_GL_H_ 21 | 22 | #include 23 | 24 | #define GlName GlObject.name 25 | 26 | extern const CommonObject GlObject; 27 | 28 | extern const luaL_Reg GlFunctions[]; 29 | 30 | extern const CommonEnum GlAttr[]; 31 | 32 | extern const CommonEnum GlProfile[]; 33 | 34 | extern const CommonEnum GlContextFlags[]; 35 | 36 | #endif /* !_LUA_SDL_GL_H_ */ 37 | -------------------------------------------------------------------------------- /src/haptic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * haptic.h -- force feedback control 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _HAPTIC_H_ 20 | #define _HAPTIC_H_ 21 | 22 | #include 23 | 24 | #define HapticName Haptic.name 25 | 26 | extern const luaL_Reg HapticFunctions[]; 27 | 28 | extern const CommonObject Haptic; 29 | 30 | extern const CommonEnum HapticType[]; 31 | 32 | extern const CommonEnum HapticDirection[]; 33 | 34 | #endif /* !_HAPTIC_H_ */ 35 | -------------------------------------------------------------------------------- /src/joystick.h: -------------------------------------------------------------------------------- 1 | /* 2 | * joystick.h -- joystick event management 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * Copyright (c) 2016 Webster Sheets 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice appear in all copies. 10 | * 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | */ 19 | 20 | #ifndef _JOYSTICK_H_ 21 | #define _JOYSTICK_H_ 22 | 23 | #include 24 | 25 | #define JoystickName Joystick.name 26 | 27 | extern const luaL_Reg JoystickFunctions[]; 28 | 29 | extern const CommonObject Joystick; 30 | 31 | extern const CommonEnum EventJoyHat[]; 32 | 33 | #if SDL_VERSION_ATLEAST(2, 0, 4) 34 | extern const CommonEnum JoystickPowerLevels[]; 35 | #endif 36 | 37 | #endif /* !_JOYSTICK_H_ */ 38 | -------------------------------------------------------------------------------- /src/keyboard.h: -------------------------------------------------------------------------------- 1 | /* 2 | * keyboard.h -- keyboard event management 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _KEYBOARD_H_ 20 | #define _KEYBOARD_H_ 21 | 22 | #include 23 | 24 | extern const luaL_Reg KeyboardFunctions[]; 25 | 26 | extern const CommonEnum KeyboardCodes[]; 27 | 28 | extern const CommonEnum KeyboardScancodes[]; 29 | 30 | extern const CommonEnum KeyboardModifiers[]; 31 | 32 | #endif /* !_EVENTS_KEYBOARD_H_ */ 33 | -------------------------------------------------------------------------------- /src/logging.c: -------------------------------------------------------------------------------- 1 | /* 2 | * logging.c -- logging routines 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include "logging.h" 22 | 23 | /* -------------------------------------------------------- 24 | * Logging private helpers 25 | * -------------------------------------------------------- */ 26 | 27 | typedef void (*LogFunc)(int, const char *, ...); 28 | 29 | static int loggingOutputFunc = LUA_REFNIL; 30 | 31 | static void * 32 | loggingCustomOutput(lua_State *L, int category, int priority, const char *msg) 33 | { 34 | lua_rawgeti(L, LUA_REGISTRYINDEX, loggingOutputFunc); 35 | lua_pushinteger(L, category); 36 | lua_pushinteger(L, priority); 37 | lua_pushstring(L, msg); 38 | lua_call(L, 3, 0); 39 | 40 | /* What is the use of that return? */ 41 | return NULL; 42 | } 43 | 44 | static int 45 | loggingLog(lua_State *L, LogFunc func) 46 | { 47 | int category = luaL_checkinteger(L, 1); 48 | const char *msg = luaL_checkstring(L, 2); 49 | 50 | func(category, "%s", msg); 51 | 52 | return 0; 53 | } 54 | 55 | /* -------------------------------------------------------- 56 | * Logging functions 57 | * -------------------------------------------------------- */ 58 | 59 | /* 60 | * SDL.log(msg) 61 | * 62 | * Arguments: 63 | * msg the message 64 | */ 65 | static int 66 | l_log(lua_State *L) 67 | { 68 | SDL_Log("%s", luaL_checkstring(L, 1)); 69 | 70 | return 0; 71 | } 72 | 73 | /* 74 | * SDL.logCritical(category, msg) 75 | * 76 | * Arguments: 77 | * category the category (SDL.logCategory) 78 | * msg the message 79 | */ 80 | static int 81 | l_logCritical(lua_State *L) 82 | { 83 | return loggingLog(L, SDL_LogCritical); 84 | } 85 | 86 | /* 87 | * SDL.logDebug(category, msg) 88 | * 89 | * Arguments: 90 | * category the category (SDL.logCategory) 91 | * msg the message 92 | */ 93 | static int 94 | l_logDebug(lua_State *L) 95 | { 96 | return loggingLog(L, SDL_LogDebug); 97 | } 98 | 99 | /* 100 | * SDL.logError(category, msg) 101 | * 102 | * Arguments: 103 | * category the category (SDL.logCategory) 104 | * msg the message 105 | */ 106 | static int 107 | l_logError(lua_State *L) 108 | { 109 | return loggingLog(L, SDL_LogError); 110 | } 111 | 112 | /* 113 | * SDL.logGetOutputFunction() 114 | * 115 | * Returns: 116 | * The function or nil 117 | */ 118 | static int 119 | l_logGetOutputFunction(lua_State *L) 120 | { 121 | if (loggingOutputFunc == LUA_REFNIL) 122 | lua_pushnil(L); 123 | else 124 | lua_rawgeti(L, LUA_REGISTRYINDEX, loggingOutputFunc); 125 | 126 | return 1; 127 | } 128 | 129 | /* 130 | * SDL.logGetPriority(category) 131 | * 132 | * Arguments: 133 | * category the category (SDL.logCategory) 134 | * 135 | * Returns: 136 | * The priority (SDL.logPriority) 137 | */ 138 | static int 139 | l_logGetPriority(lua_State *L) 140 | { 141 | int category = luaL_checkinteger(L, 1); 142 | 143 | return commonPush(L, "i", SDL_LogGetPriority(category)); 144 | } 145 | 146 | /* 147 | * SDL.logInfo(category, msg) 148 | * 149 | * Arguments: 150 | * category the category (SDL.logCategory) 151 | * msg the message 152 | */ 153 | static int 154 | l_logInfo(lua_State *L) 155 | { 156 | return loggingLog(L, SDL_LogInfo); 157 | } 158 | 159 | /* 160 | * SDL.logMessage(category, priority, msg) 161 | * 162 | * Arguments: 163 | * category the category 164 | * priority the priority 165 | * msg the message 166 | */ 167 | static int 168 | l_logMessage(lua_State *L) 169 | { 170 | int category = luaL_checkinteger(L, 1); 171 | int priority = luaL_checkinteger(L, 2); 172 | const char *msg = luaL_checkstring(L, 3); 173 | 174 | SDL_LogMessage(category, priority, "%s", msg); 175 | 176 | return 0; 177 | } 178 | 179 | /* 180 | * SDL.logResetPriorities() 181 | */ 182 | static int 183 | l_logResetPriorities(lua_State *L) 184 | { 185 | SDL_LogResetPriorities(); 186 | 187 | (void)L; 188 | 189 | return 0; 190 | } 191 | 192 | /* 193 | * SDL.logSetAllPriority(priority) 194 | * 195 | * Arguments: 196 | * priority (SDL.logPriority) 197 | */ 198 | static int 199 | l_logSetAllPriority(lua_State *L) 200 | { 201 | int priority = luaL_checkinteger(L, 1); 202 | 203 | SDL_LogSetAllPriority(priority); 204 | 205 | return 0; 206 | } 207 | 208 | /* 209 | * SDL.logSetOutputFunction(func) 210 | * 211 | * The function must have the following signature: 212 | * function log(category, priority, message) 213 | * 214 | * Arguments: 215 | * func the function 216 | */ 217 | static int 218 | l_logSetOutputFunction(lua_State *L) 219 | { 220 | luaL_checktype(L, 1, LUA_TFUNCTION); 221 | 222 | /* Remove old one if needed */ 223 | if (loggingOutputFunc != LUA_REFNIL) 224 | luaL_unref(L, LUA_REGISTRYINDEX, loggingOutputFunc); 225 | 226 | lua_pushvalue(L, 1); 227 | loggingOutputFunc = luaL_ref(L, LUA_REGISTRYINDEX); 228 | 229 | SDL_LogSetOutputFunction((SDL_LogOutputFunction)loggingCustomOutput, L); 230 | 231 | return 0; 232 | } 233 | 234 | /* 235 | * SDL.logSetPriority(category, priority) 236 | * 237 | * Arguments: 238 | * category the category (SDL.logCategory) 239 | * priority the priority (SDL.logPriority) 240 | */ 241 | static int 242 | l_logSetPriority(lua_State *L) 243 | { 244 | int category = luaL_checkinteger(L, 1); 245 | int priority = luaL_checkinteger(L, 2); 246 | 247 | SDL_LogSetPriority(category, priority); 248 | 249 | (void)L; 250 | 251 | return 0; 252 | } 253 | 254 | /* 255 | * SDL.logVerbose(category, msg) 256 | * 257 | * Arguments: 258 | * category the category (SDL.logCategory) 259 | * msg the message 260 | */ 261 | static int 262 | l_logVerbose(lua_State *L) 263 | { 264 | return loggingLog(L, SDL_LogVerbose); 265 | } 266 | 267 | /* 268 | * SDL.logWarn(category, msg) 269 | * 270 | * Arguments: 271 | * category the category (SDL.logCategory) 272 | * msg the message 273 | */ 274 | static int 275 | l_logWarn(lua_State *L) 276 | { 277 | return loggingLog(L, SDL_LogWarn); 278 | } 279 | 280 | const luaL_Reg LoggingFunctions[] = { 281 | { "log", l_log }, 282 | { "logCritical", l_logCritical }, 283 | { "logDebug", l_logDebug }, 284 | { "logError", l_logError }, 285 | { "logGetOutputFunction", l_logGetOutputFunction }, 286 | { "logGetPriority", l_logGetPriority }, 287 | { "logInfo", l_logInfo }, 288 | { "logMessage", l_logMessage }, 289 | { "logResetPriorities", l_logResetPriorities }, 290 | { "logSetAllPriority", l_logSetAllPriority }, 291 | { "logSetOutputFunction", l_logSetOutputFunction }, 292 | { "logSetPriority", l_logSetPriority }, 293 | { "logVerbose", l_logVerbose }, 294 | { "logWarn", l_logWarn }, 295 | { NULL, NULL } 296 | }; 297 | 298 | /* 299 | * SDL.logCategory 300 | */ 301 | const CommonEnum LoggingCategory[] = { 302 | { "Application", SDL_LOG_CATEGORY_APPLICATION }, 303 | { "Error", SDL_LOG_CATEGORY_ERROR }, 304 | { "System", SDL_LOG_CATEGORY_SYSTEM }, 305 | { "Audio", SDL_LOG_CATEGORY_AUDIO }, 306 | { "Video", SDL_LOG_CATEGORY_VIDEO }, 307 | { "Render", SDL_LOG_CATEGORY_RENDER }, 308 | { "Input", SDL_LOG_CATEGORY_INPUT }, 309 | { "Custom", SDL_LOG_CATEGORY_CUSTOM }, 310 | { NULL, -1 } 311 | }; 312 | 313 | /* 314 | * SDL.logPriority 315 | */ 316 | const CommonEnum LoggingPriority[] = { 317 | { "Verbose", SDL_LOG_PRIORITY_VERBOSE }, 318 | { "Debug", SDL_LOG_PRIORITY_DEBUG }, 319 | { "Info", SDL_LOG_PRIORITY_INFO }, 320 | { "Warn", SDL_LOG_PRIORITY_WARN }, 321 | { "Error", SDL_LOG_PRIORITY_ERROR }, 322 | { "Critical", SDL_LOG_PRIORITY_CRITICAL }, 323 | { NULL, -1 } 324 | }; 325 | -------------------------------------------------------------------------------- /src/logging.h: -------------------------------------------------------------------------------- 1 | /* 2 | * logging.h -- logging routines 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _LOGGING_H_ 20 | #define _LOGGING_H_ 21 | 22 | #include 23 | 24 | extern const luaL_Reg LoggingFunctions[]; 25 | 26 | extern const CommonEnum LoggingCategory[]; 27 | 28 | extern const CommonEnum LoggingPriority[]; 29 | 30 | #endif /* !_LOGGING_H_ */ 31 | -------------------------------------------------------------------------------- /src/mouse.h: -------------------------------------------------------------------------------- 1 | /* 2 | * mouse.h -- mouse event management 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * Copyright (c) 2016 Webster Sheets 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice appear in all copies. 10 | * 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | */ 19 | 20 | #ifndef _MOUSE_H_ 21 | #define _MOUSE_H_ 22 | 23 | #include 24 | 25 | #define MouseCursorName MouseCursor.name 26 | 27 | extern const luaL_Reg MouseFunctions[]; 28 | 29 | extern const CommonObject MouseCursor; 30 | 31 | extern const CommonEnum SystemCursor[]; 32 | 33 | extern const CommonEnum MouseButtons[]; 34 | 35 | extern const CommonEnum MouseMask[]; 36 | 37 | #if SDL_VERSION_ATLEAST(2, 0, 2) 38 | extern const CommonEnum MouseClick[]; 39 | #endif 40 | 41 | #endif /* !_MOUSE_H_ */ 42 | -------------------------------------------------------------------------------- /src/platform.c: -------------------------------------------------------------------------------- 1 | /* 2 | * platform.c -- platform management 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include "platform.h" 22 | 23 | /* 24 | * SDL.getPlatform() 25 | * 26 | * Returns: 27 | * The platform 28 | */ 29 | static int 30 | l_getPlatform(lua_State *L) 31 | { 32 | return commonPush(L, "s", SDL_GetPlatform()); 33 | } 34 | 35 | const struct luaL_Reg PlatformFunctions[] = { 36 | { "getPlatform", l_getPlatform }, 37 | { NULL, NULL } 38 | }; 39 | -------------------------------------------------------------------------------- /src/platform.h: -------------------------------------------------------------------------------- 1 | /* 2 | * platform.h -- platform management 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _PLATFORM_H_ 20 | #define _PLATFORM_H_ 21 | 22 | #include 23 | 24 | extern const luaL_Reg PlatformFunctions[]; 25 | 26 | #endif /* !_PLATFORM_H_ */ 27 | -------------------------------------------------------------------------------- /src/power.c: -------------------------------------------------------------------------------- 1 | /* 2 | * power.c -- power management 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | 21 | #include "power.h" 22 | 23 | /* 24 | * SDL.getPowerInfo() 25 | * 26 | * Returns: 27 | * The state (SDL.powerState) 28 | * The seconds remaining 29 | * The percentage 30 | */ 31 | static int 32 | l_getPowerInfo(lua_State *L) 33 | { 34 | int secs, pct; 35 | SDL_PowerState state; 36 | 37 | state = SDL_GetPowerInfo(&secs, &pct); 38 | 39 | lua_pushinteger(L, state); 40 | lua_pushinteger(L, secs); 41 | lua_pushinteger(L, pct); 42 | 43 | return 3; 44 | } 45 | 46 | const struct luaL_Reg PowerFunctions[] = { 47 | { "getPowerInfo", l_getPowerInfo }, 48 | { NULL, NULL } 49 | }; 50 | 51 | /* 52 | * SDL.powerState 53 | */ 54 | const CommonEnum PowerState[] = { 55 | { "Unknown", SDL_POWERSTATE_UNKNOWN }, 56 | { "OnBattery", SDL_POWERSTATE_ON_BATTERY }, 57 | { "NoBattery", SDL_POWERSTATE_NO_BATTERY }, 58 | { "Charging", SDL_POWERSTATE_CHARGING }, 59 | { "Charged", SDL_POWERSTATE_CHARGED }, 60 | { NULL, -1 } 61 | }; 62 | -------------------------------------------------------------------------------- /src/power.h: -------------------------------------------------------------------------------- 1 | /* 2 | * power.h -- power management 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _POWER_H_ 20 | #define _POWER_H_ 21 | 22 | #include 23 | 24 | extern const struct luaL_Reg PowerFunctions[]; 25 | 26 | extern const CommonEnum PowerState[]; 27 | 28 | #endif /* !_POWER_H_ */ 29 | -------------------------------------------------------------------------------- /src/rectangle.c: -------------------------------------------------------------------------------- 1 | /* 2 | * rectangle.c -- rectangle, overlap and merges 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * Copyright (c) 2016 Webster Sheets 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice appear in all copies. 10 | * 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | #include "rectangle.h" 28 | 29 | /* 30 | * SDL.enclosePoints(points, clip) 31 | * 32 | * Arguments: 33 | * points a sequence table of points 34 | * clip (optional) a clipping rectangle 35 | * 36 | * Returns: 37 | * True on success or false on failure 38 | * The rectangle or nil 39 | * The error message 40 | */ 41 | static int 42 | l_enclosePoints(lua_State *L) 43 | { 44 | SDL_Rect result, clip, *clipptr = NULL; 45 | 46 | int ret; 47 | Array points; 48 | 49 | /* Get / check arguments */ 50 | luaL_checktype(L, 1, LUA_TTABLE); 51 | 52 | if (lua_gettop(L) >= 2) { 53 | videoGetRect(L, 2, &clip); 54 | clipptr = &clip; 55 | } 56 | 57 | if (videoGetPoints(L, 1, &points) < 0) 58 | return commonPushErrno(L, 2); 59 | 60 | ret = SDL_EnclosePoints(points.data, points.length, clipptr, &result); 61 | 62 | lua_pushboolean(L, ret); 63 | videoPushRect(L, &result); 64 | 65 | /* Get rid of points */ 66 | arrayFree(&points); 67 | 68 | return 2; 69 | } 70 | 71 | /* 72 | * SDL.hasIntersection(r1, r2) 73 | * 74 | * Arguments: 75 | * r1 the first rectangle 76 | * r2 the second rectangle 77 | * 78 | * Returns: 79 | * True on intersections 80 | */ 81 | static int 82 | l_hasIntersection(lua_State *L) 83 | { 84 | SDL_Rect a, b; 85 | 86 | videoGetRect(L, 1, &a); 87 | videoGetRect(L, 2, &b); 88 | 89 | return commonPush(L, "b", SDL_HasIntersection(&a, &b)); 90 | } 91 | 92 | /* 93 | * SDL.intersectRect(r1, r2) 94 | * 95 | * Arguments: 96 | * r1 the first rectangle 97 | * r2 the second rectangle 98 | * 99 | * Returns: 100 | * True if has intersection 101 | * The result rectangle 102 | */ 103 | static int 104 | l_intersectRect(lua_State *L) 105 | { 106 | SDL_Rect a, b, result; 107 | int rvalue; 108 | 109 | videoGetRect(L, 1, &a); 110 | videoGetRect(L, 2, &b); 111 | 112 | rvalue = SDL_IntersectRect(&a, &b, &result); 113 | 114 | lua_pushboolean(L, rvalue); 115 | videoPushRect(L, &result); 116 | 117 | return 2; 118 | } 119 | 120 | /* 121 | * SDL.intersectRectAndLine(rect, x1, y1, x2, y2) 122 | * 123 | * Arguments: 124 | * rect the rectangle 125 | * x1 the starting x 126 | * y1 the starting y 127 | * x2 the ending x 128 | * y2 the ending y 129 | * 130 | * Returns: 131 | * The rectangle 132 | * The updated x1, 133 | * The updated y1, 134 | * The updated x2, 135 | * The updated y2 136 | */ 137 | static int 138 | l_intersectRectAndLine(lua_State *L) 139 | { 140 | SDL_Rect rect; 141 | int x1, y1, x2, y2, rvalue; 142 | 143 | videoGetRect(L, 1, &rect); 144 | x1 = luaL_checkinteger(L, 2); 145 | y1 = luaL_checkinteger(L, 3); 146 | x2 = luaL_checkinteger(L, 4); 147 | y2 = luaL_checkinteger(L, 5); 148 | 149 | rvalue = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2); 150 | 151 | return commonPush(L, "biiii", rvalue, x1, y1, x2, y2); 152 | } 153 | 154 | /* 155 | * SDL.rectEmpty(rect) 156 | * 157 | * Arguments: 158 | * rect the rectangle 159 | * 160 | * Returns: 161 | * True if empty 162 | */ 163 | static int 164 | l_rectEmpty(lua_State *L) 165 | { 166 | SDL_Rect rect; 167 | 168 | videoGetRect(L, 1, &rect); 169 | 170 | return commonPush(L, "b", SDL_RectEmpty(&rect)); 171 | } 172 | 173 | /* 174 | * SDL.rectEquals(r1, r2) 175 | * 176 | * Arguments: 177 | * r1 the first rectangle 178 | * r2 the second rectangle 179 | * 180 | * Returns: 181 | * True if equals 182 | */ 183 | static int 184 | l_rectEquals(lua_State *L) 185 | { 186 | SDL_Rect a, b; 187 | 188 | videoGetRect(L, 1, &a); 189 | videoGetRect(L, 2, &a); 190 | 191 | return commonPush(L, "b", SDL_RectEquals(&a, &b)); 192 | } 193 | 194 | /* 195 | * SDL.unionRect(r1, r2) 196 | * 197 | * Arguments: 198 | * r1 the first rectangle 199 | * r2 the second rectangle 200 | * 201 | * Returns: 202 | * The union rectangle 203 | */ 204 | static int 205 | l_unionRect(lua_State *L) 206 | { 207 | SDL_Rect a, b, result; 208 | 209 | videoGetRect(L, 1, &a); 210 | videoGetRect(L, 2, &a); 211 | 212 | SDL_UnionRect(&a, &b, &result); 213 | videoPushRect(L, &result); 214 | 215 | return 1; 216 | } 217 | 218 | #if SDL_VERSION_ATLEAST(2, 0, 4) 219 | /* 220 | * SDL.pointInRect(p, r) 221 | * 222 | * Arguments: 223 | * p the point 224 | * r the rectangle 225 | * 226 | * Returns: 227 | * true if p lies within r 228 | */ 229 | static int 230 | l_pointInRect(lua_State *L) 231 | { 232 | SDL_Point p; 233 | SDL_Rect r; 234 | 235 | videoGetPoint(L, 1, &p); 236 | videoGetRect(L, 2, &r); 237 | 238 | return commonPush(L, "b", SDL_PointInRect(&p, &r)); 239 | } 240 | #endif 241 | 242 | const luaL_Reg RectangleFunctions[] = { 243 | { "enclosePoints", l_enclosePoints }, 244 | { "hasIntersection", l_hasIntersection }, 245 | { "intersectRect", l_intersectRect }, 246 | { "intersectRectAndLine", l_intersectRectAndLine }, 247 | { "rectEmpty", l_rectEmpty }, 248 | { "rectEquals", l_rectEquals }, 249 | { "unionRect", l_unionRect }, 250 | #if SDL_VERSION_ATLEAST(2, 0, 4) 251 | { "pointInRect", l_pointInRect }, 252 | #endif 253 | { NULL, NULL } 254 | }; 255 | -------------------------------------------------------------------------------- /src/rectangle.h: -------------------------------------------------------------------------------- 1 | /* 2 | * rectangle.h -- rectangle, overlap and merges 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _RECTANGLE_H_ 20 | #define _RECTANGLE_H_ 21 | 22 | #include 23 | 24 | extern const luaL_Reg RectangleFunctions[]; 25 | 26 | #endif /* !_RECTANGLE_H_ */ 27 | -------------------------------------------------------------------------------- /src/renderer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * renderer.c -- 2D accelerated drawing 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _RENDERER_H_ 20 | #define _RENDERER_H_ 21 | 22 | #include 23 | 24 | #define RendererName Renderer.name 25 | 26 | extern const luaL_Reg RendererFunctions[]; 27 | 28 | extern const CommonObject Renderer; 29 | 30 | extern const CommonEnum RendererFlags[]; 31 | 32 | extern const CommonEnum RendererFlip[]; 33 | 34 | #endif /* !_RENDERER_H_ */ 35 | -------------------------------------------------------------------------------- /src/texture.c: -------------------------------------------------------------------------------- 1 | /* 2 | * texture.c -- textures management 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include "texture.h" 24 | 25 | /* -------------------------------------------------------- 26 | * Texture object methods 27 | * -------------------------------------------------------- */ 28 | 29 | /* 30 | * Texture:getAlphaMod() 31 | * 32 | * Returns: 33 | * The alpha mod integer or nil on failure 34 | * The error message 35 | */ 36 | static int 37 | l_texture_getAlphaMod(lua_State *L) 38 | { 39 | SDL_Texture *tex = commonGetAs(L, 1, TextureName, SDL_Texture *); 40 | Uint8 alpha; 41 | 42 | if (SDL_GetTextureAlphaMod(tex, &alpha) < 0) 43 | return commonPushSDLError(L, 1); 44 | 45 | return commonPush(L, "i", alpha); 46 | } 47 | 48 | /* 49 | * Texture:getBlendMode() 50 | * 51 | * Returns: 52 | * The blend mod integer or nil on failure (SDL.blendMode) 53 | * The error message 54 | */ 55 | static int 56 | l_texture_getBlendMode(lua_State *L) 57 | { 58 | SDL_Texture *tex = commonGetAs(L, 1, TextureName, SDL_Texture *); 59 | SDL_BlendMode mode; 60 | 61 | if (SDL_GetTextureBlendMode(tex, &mode) < 0) 62 | return commonPushSDLError(L, 1); 63 | 64 | return commonPush(L, "i", mode); 65 | } 66 | 67 | /* 68 | * Texture:getColorMod() 69 | * 70 | * Returns: 71 | * The color (hexadecimal) or nil 72 | * The color (table) or nil 73 | * The error message 74 | */ 75 | static int 76 | l_texture_getColorMod(lua_State *L) 77 | { 78 | SDL_Texture *tex = commonGetAs(L, 1, TextureName, SDL_Texture *); 79 | SDL_Color c; 80 | Uint32 hex; 81 | 82 | if (SDL_GetTextureColorMod(tex, &c.r, &c.g, &c.b) < 0) 83 | return commonPushSDLError(L, 2); 84 | 85 | hex = (c.r << 16) | (c.g << 8) | c.b; 86 | 87 | commonPush(L, "i", hex); 88 | videoPushColorRGB(L, &c); 89 | 90 | return 2; 91 | } 92 | 93 | static int 94 | l_texture_lock(lua_State *L) 95 | { 96 | /* XXX */ 97 | 98 | (void)L; 99 | 100 | return 0; 101 | } 102 | 103 | /* 104 | * Texture:query() 105 | * 106 | * Returns: 107 | * The format (SDL.pixelFormat) or nil 108 | * The access (SDL.textureAccess) or nil 109 | * The width or nil 110 | * The height or nil 111 | * The error message 112 | */ 113 | static int 114 | l_texture_query(lua_State *L) 115 | { 116 | SDL_Texture *tex = commonGetAs(L, 1, TextureName, SDL_Texture *); 117 | Uint32 format; 118 | int access, w, h; 119 | 120 | if (SDL_QueryTexture(tex, &format, &access, &w, &h) < 0) 121 | return commonPushSDLError(L, 4); 122 | 123 | return commonPush(L, "iiii", format, access, w, h); 124 | } 125 | 126 | /* 127 | * Texture:setAlphaMod(value) 128 | * 129 | * Arguments: 130 | * value the value 131 | * 132 | * Returns: 133 | * True on success or false 134 | * The error message 135 | */ 136 | static int 137 | l_texture_setAlphaMod(lua_State *L) 138 | { 139 | SDL_Texture *tex = commonGetAs(L, 1, TextureName, SDL_Texture *); 140 | Uint8 alpha = luaL_checkinteger(L, 2); 141 | 142 | if (SDL_SetTextureAlphaMod(tex, alpha) < 0) 143 | return commonPushSDLError(L, 1); 144 | 145 | return commonPush(L, "b", 1); 146 | } 147 | 148 | /* 149 | * Texture:setBlendMode(value) 150 | * 151 | * Arguments: 152 | * value the value (SDL.blendMode) 153 | * 154 | * Returns: 155 | * True on success or false 156 | * The error message 157 | */ 158 | static int 159 | l_texture_setBlendMode(lua_State *L) 160 | { 161 | SDL_Texture *tex = commonGetAs(L, 1, TextureName, SDL_Texture *); 162 | SDL_BlendMode mode = luaL_checkinteger(L, 2); 163 | 164 | if (SDL_SetTextureBlendMode(tex, mode) < 0) 165 | return commonPushSDLError(L, 1); 166 | 167 | return commonPush(L, "b", 1); 168 | } 169 | 170 | /* 171 | * Texture:setColorMod(value) 172 | * 173 | * Arguments: 174 | * value the color 175 | * 176 | * Returns: 177 | * True on success or false 178 | * The error message 179 | */ 180 | static int 181 | l_texture_setColorMod(lua_State *L) 182 | { 183 | SDL_Texture *tex = commonGetAs(L, 1, TextureName, SDL_Texture *); 184 | SDL_Color c; 185 | 186 | c = videoGetColorRGB(L, 2); 187 | 188 | if (SDL_SetTextureColorMod(tex, c.r, c.g, c.b) < 0) 189 | return commonPushSDLError(L, 1); 190 | 191 | return commonPush(L, "b", 1); 192 | } 193 | 194 | /* 195 | * Texture:unlock() 196 | */ 197 | static int 198 | l_texture_unlock(lua_State *L) 199 | { 200 | SDL_Texture *tex = commonGetAs(L, 1, TextureName, SDL_Texture *); 201 | 202 | SDL_UnlockTexture(tex); 203 | 204 | return 0; 205 | } 206 | 207 | static int 208 | l_texture_update(lua_State *L) 209 | { 210 | /* XXX: IMPLEMENT LATER */ 211 | 212 | (void)L; 213 | 214 | return 0; 215 | } 216 | 217 | /* -------------------------------------------------------- 218 | * Texture object metamethods 219 | * -------------------------------------------------------- */ 220 | 221 | /* 222 | * Texture:__eq() 223 | */ 224 | static int 225 | l_texture_eq(lua_State *L) 226 | { 227 | SDL_Texture *o1 = commonGetAs(L, 1, TextureName, SDL_Texture *); 228 | SDL_Texture *o2 = commonGetAs(L, 1, TextureName, SDL_Texture *); 229 | 230 | return commonPush(L, "b", o1 == o2); 231 | } 232 | 233 | /* 234 | * Texture:__gc() 235 | */ 236 | static int 237 | l_texture_gc(lua_State *L) 238 | { 239 | CommonUserdata *udata = commonGetUserdata(L, 1, TextureName); 240 | 241 | if (udata->mustdelete) 242 | SDL_DestroyTexture(udata->data); 243 | 244 | return 0; 245 | } 246 | 247 | /* 248 | * Texture:__tostring() 249 | */ 250 | static int 251 | l_texture_tostring(lua_State *L) 252 | { 253 | SDL_Texture *tex = commonGetAs(L, 1, TextureName, SDL_Texture *); 254 | Uint32 format; 255 | int access, w, h; 256 | 257 | if (SDL_QueryTexture(tex, &format, &access, &w, &h) < 0) 258 | return commonPush(L, "s", SDL_GetError()); 259 | 260 | lua_pushfstring(L, "texture: format %d, access %d, w %d, h %d", 261 | format, access, w, h); 262 | 263 | return 1; 264 | } 265 | 266 | /* -------------------------------------------------------- 267 | * Texture object definition 268 | * -------------------------------------------------------- */ 269 | 270 | const luaL_Reg TextureMethods[] = { 271 | { "getAlphaMod", l_texture_getAlphaMod }, 272 | { "getBlendMode", l_texture_getBlendMode }, 273 | { "getColorMod", l_texture_getColorMod }, 274 | { "lock", l_texture_lock }, 275 | { "query", l_texture_query }, 276 | { "setAlphaMod", l_texture_setAlphaMod }, 277 | { "setBlendMode", l_texture_setBlendMode }, 278 | { "setColorMod", l_texture_setColorMod }, 279 | { "unlock", l_texture_unlock }, 280 | { "update", l_texture_update }, 281 | { NULL, NULL } 282 | }; 283 | 284 | const luaL_Reg TextureMetamethods[] = { 285 | { "__eq", l_texture_eq }, 286 | { "__gc", l_texture_gc }, 287 | { "__tostring", l_texture_tostring }, 288 | { NULL, NULL } 289 | }; 290 | 291 | const CommonObject Texture = { 292 | "Texture", 293 | TextureMethods, 294 | TextureMetamethods 295 | }; 296 | 297 | /* 298 | * SDL.textureAccess 299 | */ 300 | const CommonEnum TextureAccess[] = { 301 | { "Static", SDL_TEXTUREACCESS_STATIC }, 302 | { "Streaming", SDL_TEXTUREACCESS_STREAMING }, 303 | { "Target", SDL_TEXTUREACCESS_TARGET }, 304 | { NULL, -1 } 305 | }; 306 | 307 | /* 308 | * SDL.textureModulate 309 | */ 310 | const CommonEnum TextureModulate[] = { 311 | { "None", SDL_TEXTUREMODULATE_NONE }, 312 | { "Color", SDL_TEXTUREMODULATE_COLOR }, 313 | { "Alpha", SDL_TEXTUREMODULATE_ALPHA }, 314 | { NULL, -1 } 315 | }; 316 | -------------------------------------------------------------------------------- /src/texture.h: -------------------------------------------------------------------------------- 1 | /* 2 | * texture.h -- textures management 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _TEXTURE_H_ 20 | #define _TEXTURE_H_ 21 | 22 | #include 23 | 24 | #define TextureName Texture.name 25 | 26 | extern const luaL_Reg TextureFunctions[]; 27 | 28 | extern const CommonObject Texture; 29 | 30 | extern const CommonEnum TextureAccess[]; 31 | 32 | extern const CommonEnum TextureModulate[]; 33 | 34 | #endif /* !_TEXTURE_H_ */ 35 | -------------------------------------------------------------------------------- /src/thread.h: -------------------------------------------------------------------------------- 1 | /* 2 | * thread.h -- thread creation management 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _THREAD_H_ 20 | #define _THREAD_H_ 21 | 22 | #include 23 | 24 | #define ThreadName Thread.name 25 | 26 | extern const luaL_Reg ThreadFunctions[]; 27 | 28 | extern const CommonObject Thread; 29 | 30 | /** 31 | * Dump a file or a function at the given index from the owner Lua state and 32 | * pushes the result to the th state. 33 | * 34 | * If everything goes wrong, it returns 2, the number of objects (to the owner 35 | * state) pushed which are nil + the error message, otherwise 0 is returned. 36 | * 37 | * @param owner the Lua state which owns the thread 38 | * @param th the Lua state where the function dumped should be pushed 39 | * @param index the function / filepath index 40 | * @return 0 or 2 41 | */ 42 | int 43 | threadDump(lua_State *owner, lua_State *th, int index); 44 | 45 | #endif /* !_THREAD_H_ */ 46 | -------------------------------------------------------------------------------- /src/timer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * timer.c -- timer routines 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include "timer.h" 20 | #include "thread.h" 21 | 22 | typedef struct Timer { 23 | SDL_TimerID id; 24 | lua_State *L; 25 | int ref; 26 | } Timer; 27 | 28 | /* 29 | * Timer:remove() 30 | * 31 | * Returns: 32 | * True if deleted 33 | */ 34 | static int 35 | l_timer_remove(lua_State *L) 36 | { 37 | Timer *t = commonGetAs(L, 1, TimerName, Timer *); 38 | int ret; 39 | 40 | ret = SDL_RemoveTimer(t->id); 41 | t->ref = -1; 42 | 43 | return commonPush(L, "b", ret); 44 | } 45 | 46 | /* 47 | * Timer:id() 48 | * 49 | * Returns: 50 | * The timer id 51 | */ 52 | static int 53 | l_timer_id(lua_State *L) 54 | { 55 | Timer *t = commonGetAs(L, 1, TimerName, Timer *); 56 | 57 | return commonPush(L, "i", t->id); 58 | } 59 | 60 | /* 61 | * Timer:__gc() 62 | */ 63 | static int 64 | l_timer_gc(lua_State *L) 65 | { 66 | Timer *t = commonGetAs(L, 1, TimerName, Timer *); 67 | 68 | if (t->ref > 0) 69 | SDL_RemoveTimer(t->id); 70 | 71 | lua_close(t->L); 72 | 73 | return 0; 74 | } 75 | 76 | static const luaL_Reg TimerMethods[] = { 77 | { "remove", l_timer_remove }, 78 | { "id", l_timer_id }, 79 | { NULL, NULL } 80 | }; 81 | 82 | static const luaL_Reg TimerMetamethods[] = { 83 | { "__gc", l_timer_gc }, 84 | { NULL, NULL } 85 | }; 86 | 87 | const CommonObject TimerObject = { 88 | "Timer", 89 | TimerMethods, 90 | TimerMetamethods 91 | }; 92 | 93 | /* --------------------------------------------------------- 94 | * Timer helpers 95 | * --------------------------------------------------------- */ 96 | 97 | static Uint32 98 | timerCallback(Uint32 interval, Timer *t) 99 | { 100 | Uint32 v = 0; 101 | 102 | lua_rawgeti(t->L, LUA_REGISTRYINDEX, t->ref); 103 | lua_pushinteger(t->L, interval); 104 | 105 | if (lua_pcall(t->L, 1, 1, 0) != LUA_OK) { 106 | SDL_LogCritical(SDL_LOG_CATEGORY_SYSTEM, "%s", lua_tostring(t->L, -1)); 107 | lua_pop(t->L, 1); 108 | } else if (lua_type(t->L, -1) == LUA_TNUMBER) 109 | v = (Uint32)lua_tonumber(t->L, -1); 110 | 111 | return v; 112 | } 113 | 114 | /* --------------------------------------------------------- 115 | * Timer functions 116 | * --------------------------------------------------------- */ 117 | 118 | /* 119 | * SDL.addTimer(interval, source) 120 | * 121 | * Arguments: 122 | * interval the interval between calls 123 | * source the path to the file or a function 124 | * 125 | * Returns: 126 | * The timer object or nil on failure 127 | * The error message 128 | */ 129 | static int 130 | l_addTimer(lua_State *L) 131 | { 132 | Uint32 interval = luaL_checkinteger(L, 1); 133 | Timer *t; 134 | 135 | if ((t = calloc(1, sizeof (Timer))) == NULL) 136 | return commonPushErrno(L, 1); 137 | 138 | t->L = luaL_newstate(); 139 | luaL_openlibs(t->L); 140 | 141 | /* Dump the function or filepath */ 142 | if (threadDump(L, t->L, 2) == 2) 143 | goto fail; 144 | 145 | /* Store the function into the ref */ 146 | t->ref = luaL_ref(t->L, LUA_REGISTRYINDEX); 147 | 148 | /* Create the timer */ 149 | if ((t->id = SDL_AddTimer(interval, (SDL_TimerCallback)timerCallback, t)) == 0) { 150 | commonPushSDLError(L, 1); 151 | goto fail; 152 | } 153 | 154 | return commonPush(L, "p", TimerName, t); 155 | 156 | fail: 157 | if (t->L) 158 | lua_close(t->L); 159 | free(t); 160 | 161 | return 2; 162 | } 163 | 164 | /* 165 | * SDL.delay(count) 166 | * 167 | * Params: 168 | * count, the number of milliseconds 169 | */ 170 | static int 171 | l_delay(lua_State *L) 172 | { 173 | SDL_Delay(luaL_checkinteger(L, 1)); 174 | 175 | return 0; 176 | } 177 | 178 | /* 179 | * SDL.getPerformanceCounter() 180 | * 181 | * Returns: 182 | * The number 183 | */ 184 | static int 185 | l_getPerformanceCounter(lua_State *L) 186 | { 187 | return commonPush(L, "i", SDL_GetPerformanceCounter()); 188 | } 189 | 190 | /* 191 | * SDL.getPerformanceFrequency() 192 | * 193 | * Returns: 194 | * The number 195 | */ 196 | static int 197 | l_getPerformanceFrequency(lua_State *L) 198 | { 199 | return commonPush(L, "i", SDL_GetPerformanceFrequency()); 200 | } 201 | 202 | /* 203 | * SDL.getTicks() 204 | * 205 | * Returns: 206 | * The ticks 207 | */ 208 | static int 209 | l_getTicks(lua_State *L) 210 | { 211 | return commonPush(L, "i", SDL_GetTicks()); 212 | } 213 | 214 | const luaL_Reg TimerFunctions[] = { 215 | { "addTimer", l_addTimer }, 216 | { "delay", l_delay }, 217 | { "getPerformanceCounter", l_getPerformanceCounter }, 218 | { "getPerformanceFrequency", l_getPerformanceFrequency }, 219 | { "getTicks", l_getTicks }, 220 | { NULL, NULL } 221 | }; 222 | -------------------------------------------------------------------------------- /src/timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * timer.h -- timer routines 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _TIMER_H_ 20 | #define _TIMER_H_ 21 | 22 | #include 23 | 24 | #define TimerName TimerObject.name 25 | 26 | extern const CommonObject TimerObject; 27 | 28 | extern const luaL_Reg TimerFunctions[]; 29 | 30 | #endif /* !_TIMER_H_ */ 31 | -------------------------------------------------------------------------------- /src/vulkan.c: -------------------------------------------------------------------------------- 1 | /* 2 | * vulkan.c -- sdl vulkan support 3 | * 4 | * Copyright (c) 2022 Sebastien MacDougall-Landry 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #include "vulkan.h" 20 | 21 | #if SDL_VERSION_ATLEAST(2, 0, 6) 22 | #include 23 | 24 | static int l_vulkan_getInstanceExtensions(lua_State *L) 25 | { 26 | SDL_Window *window = commonGetAs(L, 1, "Window", SDL_Window *); 27 | unsigned int count; 28 | 29 | if (!SDL_Vulkan_GetInstanceExtensions(window, &count, NULL)) 30 | return commonPushSDLError(L, 1); 31 | 32 | const char *names[count]; 33 | if (!SDL_Vulkan_GetInstanceExtensions(window, &count, names)) 34 | return commonPushSDLError(L, 1); 35 | 36 | lua_newtable(L); 37 | if ( (count == 0) || names[0] == NULL ) return 1; 38 | for (unsigned int i = 0; i < count; i++) 39 | { 40 | lua_pushstring(L, names[i]); 41 | lua_rawseti(L, -2, i+1); 42 | } 43 | 44 | return 1; 45 | } 46 | 47 | #endif 48 | 49 | const luaL_Reg VulkanFunctions[] = { 50 | #if SDL_VERSION_ATLEAST(2, 0, 6) 51 | { "vkGetInstanceExtensions", l_vulkan_getInstanceExtensions }, 52 | #endif 53 | { NULL, NULL } 54 | }; 55 | 56 | -------------------------------------------------------------------------------- /src/vulkan.h: -------------------------------------------------------------------------------- 1 | /* 2 | * vulkan.h -- sdl vulkan support 3 | * 4 | * Copyright (c) 2022 Sebastien MacDougall-Landry 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _VULKAN_H_ 20 | #define _VULKAN_H_ 21 | 22 | #include 23 | 24 | extern const luaL_Reg VulkanFunctions[]; 25 | 26 | #endif /* !_VULKAN_H_ */ 27 | -------------------------------------------------------------------------------- /src/window.h: -------------------------------------------------------------------------------- 1 | /* 2 | * window.h -- window management 3 | * 4 | * Copyright (c) 2013, 2014 David Demelier 5 | * Copyright (c) 2016 Webster Sheets 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice appear in all copies. 10 | * 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | */ 19 | 20 | #ifndef _WINDOW_H_ 21 | #define _WINDOW_H_ 22 | 23 | #include 24 | 25 | #define WindowName Window.name 26 | 27 | extern const luaL_Reg WindowFunctions[]; 28 | 29 | extern const CommonObject Window; 30 | 31 | extern const CommonEnum WindowFlags[]; 32 | 33 | #if SDL_VERSION_ATLEAST(2, 0, 4) 34 | 35 | extern const CommonEnum HitTestResults[]; 36 | 37 | #endif 38 | 39 | #endif /* !_WINDOW_H_ */ 40 | -------------------------------------------------------------------------------- /tutorials/01-initialization/tutorial.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- tutorial.lua -- 01 initialization 3 | -- 4 | 5 | -- Load SDL module 6 | local SDL = require "SDL" 7 | 8 | -- Initialize video and audio 9 | local ret, err = SDL.init { 10 | SDL.flags.Video, 11 | SDL.flags.Audio 12 | } 13 | 14 | if not ret then 15 | error(err) 16 | end 17 | 18 | -- Show the version 19 | print(string.format("SDL %d.%d.%d", 20 | SDL.VERSION_MAJOR, 21 | SDL.VERSION_MINOR, 22 | SDL.VERSION_PATCH 23 | )) 24 | 25 | -- Close everything 26 | SDL.quit() 27 | -------------------------------------------------------------------------------- /tutorials/02-window/tutorial.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- tutorial.lua -- 02 opening a window 3 | -- 4 | 5 | local SDL = require "SDL" 6 | 7 | local ret, err = SDL.init { SDL.flags.Video } 8 | if not ret then 9 | error(err) 10 | end 11 | 12 | local win, err = SDL.createWindow { 13 | title = "02 - Opening a window", -- optional 14 | width = 320, -- optional 15 | height = 320, -- optional 16 | flags = { SDL.window.Resizable } -- optional 17 | } 18 | 19 | if not win then 20 | error(err) 21 | end 22 | 23 | -- Let the window opened a bit 24 | SDL.delay(5000) 25 | -------------------------------------------------------------------------------- /tutorials/03-events/tutorial.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- tutorial.lua -- 03 polling events 3 | -- 4 | 5 | local SDL = require "SDL" 6 | 7 | local ret, err = SDL.init { SDL.flags.Video } 8 | if not ret then 9 | error(err) 10 | end 11 | 12 | local win, err = SDL.createWindow { 13 | title = "03 - Polling events", -- optional 14 | width = 320, -- optional 15 | height = 320, -- optional 16 | flags = { SDL.window.Resizable } -- optional 17 | } 18 | 19 | if not win then 20 | error(err) 21 | end 22 | 23 | local running = true 24 | 25 | while running do 26 | -- 27 | -- Iterate over all events, this function does not block. 28 | -- 29 | for e in SDL.pollEvent() do 30 | if e.type == SDL.event.Quit then 31 | running = false 32 | elseif e.type == SDL.event.KeyDown then 33 | print(string.format("key down: %d -> %s", e.keysym.sym, SDL.getKeyName(e.keysym.sym))) 34 | elseif e.type == SDL.event.MouseWheel then 35 | print(string.format("mouse wheel: %d, x=%d, y=%d", e.which, e.x, e.y)) 36 | elseif e.type == SDL.event.MouseButtonDown then 37 | print(string.format("mouse button down: %d, x=%d, y=%d", e.button, e.x, e.y)) 38 | elseif e.type == SDL.event.MouseMotion then 39 | print(string.format("mouse motion: x=%d, y=%d", e.x, e.y)) 40 | end 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /tutorials/04-drawing/Lua-SDL2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/tutorials/04-drawing/Lua-SDL2.png -------------------------------------------------------------------------------- /tutorials/04-drawing/tutorial.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- tutorial.lua -- 03 polling events 3 | -- 4 | 5 | local SDL = require "SDL" 6 | local image = require "SDL.image" 7 | 8 | -- 9 | -- Small wrapper to check if the SDL function succeed, if not 10 | -- we exit the program. 11 | -- 12 | -- SDL functions that fails usually return the values as nil and the last 13 | -- argument is the error message. 14 | -- 15 | local function trySDL(func, ...) 16 | local t = { func(...) } 17 | 18 | if not t[1] then 19 | error(t[#t]) 20 | end 21 | 22 | return table.unpack(t) 23 | end 24 | 25 | -- Initialize SDL and SDL_image 26 | trySDL(SDL.init, { SDL.flags.Video }) 27 | 28 | -- SDL_image returns the table with the loaded formats 29 | local formats, ret, err = image.init { image.flags.PNG } 30 | if not formats[image.flags.PNG] then 31 | error(err) 32 | end 33 | 34 | -- Initialize the window 35 | local win = trySDL(SDL.createWindow, { 36 | title = "04 - Drawing image", 37 | width = 256, 38 | height = 256, 39 | flags = { SDL.flags.OpenGL } 40 | }) 41 | 42 | -- Create the renderer 43 | local rdr = trySDL(SDL.createRenderer, win, -1) 44 | 45 | rdr:setDrawColor(0xFFFFFF) 46 | 47 | -- Load the image as a surface 48 | local img = trySDL(image.load, "Lua-SDL2.png") 49 | 50 | -- Convert the image surface to texture 51 | local logo = trySDL(rdr.createTextureFromSurface, rdr, img) 52 | 53 | for i = 1, 50 do 54 | -- Draw it 55 | rdr:clear() 56 | rdr:copy(logo) 57 | rdr:present() 58 | 59 | SDL.delay(100) 60 | end 61 | 62 | SDL.quit() 63 | 64 | image.quit() 65 | -------------------------------------------------------------------------------- /tutorials/05-sound/gun.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/tutorials/05-sound/gun.wav -------------------------------------------------------------------------------- /tutorials/05-sound/tutorial.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- tutorial.lua -- 05 playing sound 3 | -- 4 | 5 | local SDL = require "SDL" 6 | local mixer = require "SDL.mixer" 7 | 8 | local function trySDL(func, ...) 9 | local t = { func(...) } 10 | 11 | if not t[1] then 12 | error(t[#t]) 13 | end 14 | 15 | return table.unpack(t) 16 | end 17 | 18 | trySDL(SDL.init, { SDL.flags.Video }) 19 | 20 | local win = trySDL(SDL.createWindow, { 21 | title = "05 - Playing sound", -- optional 22 | width = 320, -- optional 23 | height = 320, -- optional 24 | }) 25 | 26 | -- Open the audio 27 | trySDL(mixer.openAudio, 44100, SDL.audioFormat.S16, 2, 1024) 28 | 29 | -- Open the sound 30 | local sound = trySDL(mixer.loadWAV, "gun.wav") 31 | 32 | -- Play the sound indefinitely 33 | sound:playChannel(1) 34 | 35 | -- Let the window opened a bit 36 | SDL.delay(5000) 37 | 38 | SDL.quit() 39 | mixer.quit() 40 | -------------------------------------------------------------------------------- /tutorials/06-text/DejaVuSans.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/tutorials/06-text/DejaVuSans.ttf -------------------------------------------------------------------------------- /tutorials/06-text/tutorial.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- tutorial.lua -- 06 writing text 3 | -- 4 | 5 | local SDL = require "SDL" 6 | local ttf = require "SDL.ttf" 7 | 8 | local function trySDL(func, ...) 9 | local t = { func(...) } 10 | 11 | if not t[1] then 12 | error(t[#t]) 13 | end 14 | 15 | return table.unpack(t) 16 | end 17 | 18 | trySDL(SDL.init, { SDL.flags.Video }) 19 | trySDL(ttf.init) 20 | 21 | -- Create the window 22 | local win = trySDL(SDL.createWindow, { 23 | title = "06 - Drawing text", -- optional 24 | width = 160, -- optional 25 | height = 80, -- optional 26 | }) 27 | 28 | -- Create the renderer 29 | local rdr = trySDL(SDL.createRenderer, win, -1) 30 | 31 | -- Open the font 32 | local font = trySDL(ttf.open, "DejaVuSans.ttf", 24) 33 | 34 | -- Create some text 35 | local w, h = trySDL(font.sizeText, "Lua-SDL2", t) 36 | local s = trySDL(font.renderUtf8, font, "Lua-SDL2", "solid", 0xFFFFFF) 37 | 38 | -- Convert to texture and show 39 | local text = trySDL(rdr.createTextureFromSurface, rdr, s) 40 | 41 | for i = 1, 50 do 42 | rdr:clear() 43 | 44 | -- If a rectangle is not specified, it defaults to the clipping rectangle 45 | -- of the source or destination, respectively. 46 | if i%20 < 10 then 47 | rdr:copy(text) 48 | else 49 | rdr:copy(text, nil, {x=0, y=0, w=w, h=h}) 50 | end 51 | 52 | rdr:present() 53 | 54 | SDL.delay(100) 55 | end 56 | 57 | SDL.quit() 58 | ttf.quit() 59 | -------------------------------------------------------------------------------- /tutorials/07-bouncing/Lua-SDL2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/tutorials/07-bouncing/Lua-SDL2.png -------------------------------------------------------------------------------- /tutorials/07-bouncing/tutorial.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- tutorial.lua -- 07 logo bouncing 3 | -- 4 | 5 | local SDL = require "SDL" 6 | local image = require "SDL.image" 7 | 8 | local running = true 9 | local graphics = { } 10 | local pos = { } 11 | local dir = { 1, 1 } 12 | local velocity = 2 13 | local width = 640 14 | local height = 480 15 | 16 | local function initialize() 17 | local ret, err = SDL.init { SDL.flags.Video } 18 | if not ret then 19 | error(err) 20 | end 21 | 22 | local ret, err = image.init { image.flags.PNG } 23 | if not ret then 24 | error(err) 25 | end 26 | 27 | local win, err = SDL.createWindow { 28 | title = "07 - Bouncing logo", 29 | width = width, 30 | height = height 31 | } 32 | 33 | if not win then 34 | error(err) 35 | end 36 | 37 | local rdr, err = SDL.createRenderer(win, -1) 38 | if not rdr then 39 | error(err) 40 | end 41 | 42 | -- Set to white for the logo 43 | rdr:setDrawColor(0xFFFFFF) 44 | 45 | local img, ret = image.load("Lua-SDL2.png") 46 | if not img then 47 | error(err) 48 | end 49 | 50 | local logo, err = rdr:createTextureFromSurface(img) 51 | if not logo then 52 | error(err) 53 | end 54 | 55 | -- Store in global graphics 56 | graphics.win = win 57 | graphics.rdr = rdr 58 | graphics.logo = logo 59 | 60 | -- Get the size of the logo 61 | local f, a, w, h = logo:query() 62 | 63 | pos.x = width / 2 - w / 2 64 | pos.y = height / 2 - h / 2 65 | pos.w = 256 66 | pos.h = 256 67 | end 68 | 69 | initialize() 70 | 71 | while running do 72 | for e in SDL.pollEvent() do 73 | if e.type == SDL.event.Quit then 74 | running = false 75 | end 76 | end 77 | 78 | graphics.rdr:clear() 79 | graphics.rdr:copy(graphics.logo, nil, pos) 80 | graphics.rdr:present() 81 | 82 | pos.x = pos.x + dir[1] * velocity 83 | pos.y = pos.y + dir[2] * velocity 84 | 85 | -- When we hit a wall, bounce. 86 | if (dir[1] > 0 and pos.x > width - 256) 87 | or (dir[1] < 0 and pos.x <= 0) then 88 | dir[1] = -dir[1] 89 | end 90 | 91 | if (dir[2] > 0 and pos.y > height - 256) 92 | or (dir[2] < 0 and pos.y <= 0) then 93 | dir[2] = -dir[2] 94 | end 95 | 96 | SDL.delay(20) 97 | end 98 | -------------------------------------------------------------------------------- /tutorials/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # CMakeLists.txt -- build system for LuaSDL2 3 | # 4 | # Copyright (c) 2013, 2014 David Demelier 5 | # 6 | # Permission to use, copy, modify, and/or distribute this software for any 7 | # purpose with or without fee is hereby granted, provided that the above 8 | # copyright notice and this permission notice appear in all copies. 9 | # 10 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | # 18 | 19 | project(tutorials C) 20 | 21 | # Option to enable / disable examples installation 22 | option(WITH_DOCS "Installation of tutorials" On) 23 | 24 | set( 25 | DIRECTORIES 26 | 01-initialization 27 | 02-window 28 | 03-events 29 | 04-drawing 30 | 05-sound 31 | 06-text 32 | 07-bouncing 33 | ) 34 | 35 | if (WITH_DOCS) 36 | install( 37 | DIRECTORY ${DIRECTORIES} 38 | DESTINATION ${WITH_DOCSDIR}/tutorials 39 | ) 40 | endif () 41 | -------------------------------------------------------------------------------- /windows/32/SDL2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/32/SDL2.dll -------------------------------------------------------------------------------- /windows/32/SDL2_image.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/32/SDL2_image.dll -------------------------------------------------------------------------------- /windows/32/SDL2_mixer.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/32/SDL2_mixer.dll -------------------------------------------------------------------------------- /windows/32/SDL2_net.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/32/SDL2_net.dll -------------------------------------------------------------------------------- /windows/32/SDL2_ttf.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/32/SDL2_ttf.dll -------------------------------------------------------------------------------- /windows/32/libFLAC-8.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/32/libFLAC-8.dll -------------------------------------------------------------------------------- /windows/32/libfreetype-6.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/32/libfreetype-6.dll -------------------------------------------------------------------------------- /windows/32/libjpeg-9.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/32/libjpeg-9.dll -------------------------------------------------------------------------------- /windows/32/libmikmod-2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/32/libmikmod-2.dll -------------------------------------------------------------------------------- /windows/32/libmodplug-1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/32/libmodplug-1.dll -------------------------------------------------------------------------------- /windows/32/libogg-0.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/32/libogg-0.dll -------------------------------------------------------------------------------- /windows/32/libpng16-16.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/32/libpng16-16.dll -------------------------------------------------------------------------------- /windows/32/libtiff-5.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/32/libtiff-5.dll -------------------------------------------------------------------------------- /windows/32/libvorbis-0.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/32/libvorbis-0.dll -------------------------------------------------------------------------------- /windows/32/libvorbisfile-3.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/32/libvorbisfile-3.dll -------------------------------------------------------------------------------- /windows/32/libwebp-4.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/32/libwebp-4.dll -------------------------------------------------------------------------------- /windows/32/lua.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/32/lua.dll -------------------------------------------------------------------------------- /windows/32/smpeg2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/32/smpeg2.dll -------------------------------------------------------------------------------- /windows/32/zlib1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/32/zlib1.dll -------------------------------------------------------------------------------- /windows/64/SDL2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/64/SDL2.dll -------------------------------------------------------------------------------- /windows/64/SDL2_image.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/64/SDL2_image.dll -------------------------------------------------------------------------------- /windows/64/SDL2_mixer.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/64/SDL2_mixer.dll -------------------------------------------------------------------------------- /windows/64/SDL2_net.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/64/SDL2_net.dll -------------------------------------------------------------------------------- /windows/64/SDL2_ttf.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/64/SDL2_ttf.dll -------------------------------------------------------------------------------- /windows/64/libFLAC-8.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/64/libFLAC-8.dll -------------------------------------------------------------------------------- /windows/64/libfreetype-6.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/64/libfreetype-6.dll -------------------------------------------------------------------------------- /windows/64/libjpeg-9.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/64/libjpeg-9.dll -------------------------------------------------------------------------------- /windows/64/libmikmod-2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/64/libmikmod-2.dll -------------------------------------------------------------------------------- /windows/64/libmodplug-1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/64/libmodplug-1.dll -------------------------------------------------------------------------------- /windows/64/libogg-0.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/64/libogg-0.dll -------------------------------------------------------------------------------- /windows/64/libpng16-16.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/64/libpng16-16.dll -------------------------------------------------------------------------------- /windows/64/libtiff-5.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/64/libtiff-5.dll -------------------------------------------------------------------------------- /windows/64/libvorbis-0.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/64/libvorbis-0.dll -------------------------------------------------------------------------------- /windows/64/libvorbisfile-3.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/64/libvorbisfile-3.dll -------------------------------------------------------------------------------- /windows/64/libwebp-4.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/64/libwebp-4.dll -------------------------------------------------------------------------------- /windows/64/lua.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/64/lua.dll -------------------------------------------------------------------------------- /windows/64/smpeg2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/64/smpeg2.dll -------------------------------------------------------------------------------- /windows/64/zlib1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/64/zlib1.dll -------------------------------------------------------------------------------- /windows/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # CMakeLists.txt -- build system for LuaSDL2 3 | # 4 | # Copyright (c) 2013, 2014 David Demelier 5 | # 6 | # Permission to use, copy, modify, and/or distribute this software for any 7 | # purpose with or without fee is hereby granted, provided that the above 8 | # copyright notice and this permission notice appear in all copies. 9 | # 10 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | # 18 | 19 | # Install DLL corresponding to the architecture 20 | if (CMAKE_SIZEOF_VOID_P MATCHES "8") 21 | if (MINGW) 22 | install(DIRECTORY mingw-64/ DESTINATION bin) 23 | else () 24 | install(DIRECTORY 64/ DESTINATION bin) 25 | endif () 26 | else () 27 | if (MINGW) 28 | install(DIRECTORY mingw-64/ DESTINATION bin) 29 | else () 30 | install(DIRECTORY 32/ DESTINATION bin) 31 | endif () 32 | endif () -------------------------------------------------------------------------------- /windows/mingw-32/SDL2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-32/SDL2.dll -------------------------------------------------------------------------------- /windows/mingw-32/SDL2_image.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-32/SDL2_image.dll -------------------------------------------------------------------------------- /windows/mingw-32/SDL2_mixer.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-32/SDL2_mixer.dll -------------------------------------------------------------------------------- /windows/mingw-32/SDL2_net.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-32/SDL2_net.dll -------------------------------------------------------------------------------- /windows/mingw-32/SDL2_ttf.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-32/SDL2_ttf.dll -------------------------------------------------------------------------------- /windows/mingw-32/libFLAC-8.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-32/libFLAC-8.dll -------------------------------------------------------------------------------- /windows/mingw-32/libfreetype-6.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-32/libfreetype-6.dll -------------------------------------------------------------------------------- /windows/mingw-32/libjpeg-9.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-32/libjpeg-9.dll -------------------------------------------------------------------------------- /windows/mingw-32/libmodplug-1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-32/libmodplug-1.dll -------------------------------------------------------------------------------- /windows/mingw-32/libogg-0.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-32/libogg-0.dll -------------------------------------------------------------------------------- /windows/mingw-32/libpng16-16.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-32/libpng16-16.dll -------------------------------------------------------------------------------- /windows/mingw-32/libtiff-5.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-32/libtiff-5.dll -------------------------------------------------------------------------------- /windows/mingw-32/libvorbis-0.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-32/libvorbis-0.dll -------------------------------------------------------------------------------- /windows/mingw-32/libvorbisfile-3.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-32/libvorbisfile-3.dll -------------------------------------------------------------------------------- /windows/mingw-32/libwebp-4.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-32/libwebp-4.dll -------------------------------------------------------------------------------- /windows/mingw-32/lua.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-32/lua.dll -------------------------------------------------------------------------------- /windows/mingw-32/smpeg2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-32/smpeg2.dll -------------------------------------------------------------------------------- /windows/mingw-32/zlib1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-32/zlib1.dll -------------------------------------------------------------------------------- /windows/mingw-64/SDL2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-64/SDL2.dll -------------------------------------------------------------------------------- /windows/mingw-64/SDL2_image.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-64/SDL2_image.dll -------------------------------------------------------------------------------- /windows/mingw-64/SDL2_mixer.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-64/SDL2_mixer.dll -------------------------------------------------------------------------------- /windows/mingw-64/SDL2_net.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-64/SDL2_net.dll -------------------------------------------------------------------------------- /windows/mingw-64/SDL2_ttf.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-64/SDL2_ttf.dll -------------------------------------------------------------------------------- /windows/mingw-64/libFLAC-8.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-64/libFLAC-8.dll -------------------------------------------------------------------------------- /windows/mingw-64/libfreetype-6.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-64/libfreetype-6.dll -------------------------------------------------------------------------------- /windows/mingw-64/libjpeg-9.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-64/libjpeg-9.dll -------------------------------------------------------------------------------- /windows/mingw-64/libmikmod-2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-64/libmikmod-2.dll -------------------------------------------------------------------------------- /windows/mingw-64/libmodplug-1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-64/libmodplug-1.dll -------------------------------------------------------------------------------- /windows/mingw-64/libogg-0.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-64/libogg-0.dll -------------------------------------------------------------------------------- /windows/mingw-64/libpng16-16.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-64/libpng16-16.dll -------------------------------------------------------------------------------- /windows/mingw-64/libtiff-5.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-64/libtiff-5.dll -------------------------------------------------------------------------------- /windows/mingw-64/libvorbis-0.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-64/libvorbis-0.dll -------------------------------------------------------------------------------- /windows/mingw-64/libvorbisfile-3.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-64/libvorbisfile-3.dll -------------------------------------------------------------------------------- /windows/mingw-64/libwebp-4.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-64/libwebp-4.dll -------------------------------------------------------------------------------- /windows/mingw-64/lua.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-64/lua.dll -------------------------------------------------------------------------------- /windows/mingw-64/smpeg2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-64/smpeg2.dll -------------------------------------------------------------------------------- /windows/mingw-64/zlib1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tangent128/luasdl2/9160346c71fb313086a3160ba1cdc23ed79252ed/windows/mingw-64/zlib1.dll --------------------------------------------------------------------------------