Last active
October 16, 2019 16:56
-
-
Save liquidev/978cf0094f6a08e2921c0617da7e71a4 to your computer and use it in GitHub Desktop.
Nimterop SDL2 wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## An SDL2 wrapper using nimterop. | |
import os | |
import nimterop/build | |
import nimterop/cimport | |
const | |
Base = getProjectCacheDir("sdl2") | |
setDefines(@[ | |
"SDLStd" | |
]) | |
getHeader("SDL2/SDL.h", | |
giturl = "https://github.com/SDL-mirror/SDL", | |
dlurl = "http://libsdl.org/release/SDL2-$1.zip", | |
outdir = Base, | |
altNames = "SDL2") | |
cPlugin: | |
import strutils | |
const NoPrefixStripping = [ | |
"SDL_bool", "SDL_floor" | |
] | |
proc onSymbol*(sym: var Symbol) {.exportc, dynlib.} = | |
sym.name = sym.name.replace("__", "_").strip(chars = {'_'}) | |
if sym.name notin NoPrefixStripping: | |
sym.name.removePrefix("SDL_") | |
if sym.name.startsWith("GL") and sym.kind == nskType: | |
sym.name[0..1] = "gl" | |
if sym.name.endsWith("Event") or sym.name.endsWith("Update") or | |
sym.name == "Quit": | |
sym.name.insert("X", 0) | |
cOverride: | |
type | |
BlitMap = pointer | |
HapticDirection = object | |
`type`: uint8 | |
dir: int32 | |
RWops = pointer | |
GameControllerAxis = enum | |
CONTROLLER_AXIS_INVALID | |
CONTROLLER_AXIS_LEFTX | |
CONTROLLER_AXIS_LEFTY | |
CONTROLLER_AXIS_RIGHTX | |
CONTROLLER_AXIS_RIGHTY | |
CONTROLLER_AXIS_TRIGGERLEFT | |
CONTROLLER_AXIS_TRIGGERRIGHT | |
CONTROLLER_AXIS_MAX | |
GameControllerButton = enum | |
CONTROLLER_BUTTON_INVALID | |
CONTROLLER_BUTTON_A | |
CONTROLLER_BUTTON_B | |
CONTROLLER_BUTTON_X | |
CONTROLLER_BUTTON_Y | |
CONTROLLER_BUTTON_BACK | |
CONTROLLER_BUTTON_GUIDE | |
CONTROLLER_BUTTON_START | |
CONTROLLER_BUTTON_LEFTSTICK | |
CONTROLLER_BUTTON_RIGHTSTICK | |
CONTROLLER_BUTTON_LEFTSHOULDER | |
CONTROLLER_BUTTON_RIGHTSHOULDER | |
CONTROLLER_BUTTON_DPAD_UP | |
CONTROLLER_BUTTON_DPAD_DOWN | |
CONTROLLER_BUTTON_DPAD_LEFT | |
CONTROLLER_BUTTON_DPAD_RIGHT | |
CONTROLLER_BUTTON_MAX | |
GameControllerButtonBind = GameControllerButton | |
Haptic = pointer | |
cImport(SDLPath, recurse = true, dynlib = "SDLLPath") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment