WIP: not working
This commit is contained in:
commit
c5af3b2214
6 changed files with 455 additions and 0 deletions
1
nim.cfg
Normal file
1
nim.cfg
Normal file
|
|
@ -0,0 +1 @@
|
|||
-d:SDL_DL -d:SDL_Static -d:SDL_image_DL -d:SDL_mixer_DL
|
||||
16
nim_sdl2.nimble
Normal file
16
nim_sdl2.nimble
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# Package
|
||||
|
||||
version = "0.1.0"
|
||||
author = "Joey Yakimowich-Payne"
|
||||
description = "SDL2 Autogenerated wrapper"
|
||||
license = "MIT"
|
||||
srcDir = "src"
|
||||
|
||||
|
||||
|
||||
# Dependencies
|
||||
|
||||
requires "nim >= 1.0.6", "nimterop#head"
|
||||
|
||||
task buildSDL2, "Build SDL2 example":
|
||||
exec "nimble c -f -r src/nim_sdl2/wrapper.nim"
|
||||
176
src/nim_sdl2/wrapper.nim
Normal file
176
src/nim_sdl2/wrapper.nim
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
import os
|
||||
import nimterop/[cimport, build]
|
||||
|
||||
const
|
||||
baseDir = currentSourcePath.parentDir().parentDir().parentDir()
|
||||
srcDir = baseDir/"build"/"sdl2"
|
||||
|
||||
getHeader(
|
||||
"SDL.h",
|
||||
dlurl = "https://www.libsdl.org/release/SDL2-2.0.12.tar.gz",
|
||||
outdir = srcDir
|
||||
)
|
||||
|
||||
static:
|
||||
cDebug()
|
||||
cDisableCaching()
|
||||
# # let contents = readFile(srcDir/"include/SDL_gpu.h")
|
||||
# # let newContents = contents.replace(re"""#include "SDL.h"""", "#include <SDL2/SDL.h>", limit=1).
|
||||
# # replace(re"""#include "begin_code.h"""", "", limit=1).
|
||||
# # replace(re"""#include "close_code.h"""", "", limit=1)
|
||||
|
||||
# # writeFile(srcDir/"include/SDL_gpu.h", newContents)
|
||||
|
||||
cOverride:
|
||||
const KEYCODE_UNDERSCORE* = ('_').KeyCodeEnum
|
||||
|
||||
type
|
||||
BlitMap* {.incompleteStruct.} = object
|
||||
RWops* {.incompleteStruct.} = object
|
||||
|
||||
GameControllerBindType* = enum
|
||||
CONTROLLER_BINDTYPE_NONE = 0,
|
||||
CONTROLLER_BINDTYPE_BUTTON,
|
||||
CONTROLLER_BINDTYPE_AXIS,
|
||||
CONTROLLER_BINDTYPE_HAT
|
||||
|
||||
ButtonBindHat* = object
|
||||
hat*: int
|
||||
hatMask*: int
|
||||
|
||||
GameControllerButtonBind* = object
|
||||
case bindType*: GameControllerBindType
|
||||
of CONTROLLER_BINDTYPE_BUTTON:
|
||||
button*: cint
|
||||
of CONTROLLER_BINDTYPE_AXIS:
|
||||
axis*: cint
|
||||
of CONTROLLER_BINDTYPE_HAT:
|
||||
hat*: ButtonBindHat
|
||||
of CONTROLLER_BINDTYPE_NONE:
|
||||
discard
|
||||
|
||||
# This should work, but also overrides some types
|
||||
# Nimterop bug? @genotrance, comment these out
|
||||
# and uncomment the checks in onSymbol for it to kind of work
|
||||
# (it compiles but overrides nim types)
|
||||
Uint64* = uint64
|
||||
Uint32* = uint32
|
||||
Uint16* = uint16
|
||||
Uint8* = uint8
|
||||
|
||||
Sint64* = int64
|
||||
Sint32* = int32
|
||||
Sint16* = int16
|
||||
Sint8* = int8
|
||||
Bool* = bool
|
||||
|
||||
cPlugin:
|
||||
import strutils, nre
|
||||
import sets
|
||||
|
||||
const EVENT_TYPES = toHashSet([
|
||||
"FIRSTEVENT",
|
||||
"QUIT",
|
||||
"APP_TERMINATING",
|
||||
"APP_LOWMEMORY",
|
||||
"APP_WILLENTERBACKGROUND",
|
||||
"APP_DIDENTERBACKGROUND",
|
||||
"APP_WILLENTERFOREGROUND",
|
||||
"APP_DIDENTERFOREGROUND",
|
||||
"DISPLAYEVENT",
|
||||
"WINDOWEVENT",
|
||||
"SYSWMEVENT",
|
||||
"KEYDOWN",
|
||||
"KEYUP",
|
||||
"TEXTEDITING",
|
||||
"TEXTINPUT",
|
||||
"KEYMAPCHANGED",
|
||||
"MOUSEMOTION",
|
||||
"MOUSEBUTTONDOWN",
|
||||
"MOUSEBUTTONUP",
|
||||
"MOUSEWHEEL",
|
||||
"JOYAXISMOTION",
|
||||
"JOYBALLMOTION",
|
||||
"JOYHATMOTION",
|
||||
"JOYBUTTONDOWN",
|
||||
"JOYBUTTONUP",
|
||||
"JOYDEVICEADDED",
|
||||
"JOYDEVICEREMOVED",
|
||||
"CONTROLLERAXISMOTION",
|
||||
"CONTROLLERBUTTONDOWN",
|
||||
"CONTROLLERBUTTONUP",
|
||||
"CONTROLLERDEVICEADDED",
|
||||
"CONTROLLERDEVICEREMOVED",
|
||||
"CONTROLLERDEVICEREMAPPED",
|
||||
"FINGERDOWN",
|
||||
"FINGERUP",
|
||||
"FINGERMOTION",
|
||||
"DOLLARGESTURE",
|
||||
"DOLLARRECORD",
|
||||
"MULTIGESTURE",
|
||||
"CLIPBOARDUPDATE",
|
||||
"DROPFILE",
|
||||
"DROPTEXT",
|
||||
"DROPBEGIN",
|
||||
"DROPCOMPLETE",
|
||||
"AUDIODEVICEADDED",
|
||||
"AUDIODEVICEREMOVED",
|
||||
"SENSORUPDATE",
|
||||
"RENDER_TARGETS_RESET",
|
||||
"RENDER_DEVICE_RESET",
|
||||
"USEREVENT",
|
||||
"LASTEVENT",
|
||||
])
|
||||
|
||||
# Symbol renaming examples
|
||||
proc onSymbol*(sym: var Symbol) {.exportc, dynlib.} =
|
||||
# Get rid of leading and trailing underscores
|
||||
# sym.name = sym.name.strip(chars = {'_'})
|
||||
|
||||
# Remove prefixes or suffixes from procs
|
||||
if sym.name == "__MACOSX__":
|
||||
sym.name = "MACOSX"
|
||||
if sym.kind == nskProc or sym.kind == nskType or sym.kind == nskConst:
|
||||
if sym.name != "_":
|
||||
sym.name = sym.name.replace(re"^_+", "")
|
||||
sym.name = sym.name.replace(re"_+$", "")
|
||||
sym.name = sym.name.replace(re"^SDL_", "")
|
||||
|
||||
if sym.name.startsWith("SDLK_"):
|
||||
sym.name = sym.name.replace("SDLK_", "KEYCODE_")
|
||||
|
||||
if EVENT_TYPES.contains(sym.name):
|
||||
sym.name = "EVENT_" & sym.name
|
||||
|
||||
if sym.name == "ThreadID":
|
||||
sym.name = "CurrentThreadID"
|
||||
if sym.name == "GLContextResetNotification":
|
||||
sym.name = "GLContextResetNotificationEnum"
|
||||
if sym.name == "KeyCode":
|
||||
sym.name = "KeyCodeEnum"
|
||||
|
||||
# if sym.name == "Uint64":
|
||||
# sym.name = "uint64"
|
||||
# if sym.name == "Uint32":
|
||||
# sym.name = "uint32"
|
||||
# if sym.name == "Uint16":
|
||||
# sym.name = "uint16"
|
||||
# if sym.name == "Uint8":
|
||||
# sym.name = "uint8"
|
||||
|
||||
# if sym.name == "Sint64":
|
||||
# sym.name = "int64"
|
||||
# if sym.name == "Sint32":
|
||||
# sym.name = "int32"
|
||||
# if sym.name == "Sint16":
|
||||
# sym.name = "int16"
|
||||
# if sym.name == "Sint8":
|
||||
# sym.name = "int8"
|
||||
# if sym.name == "Bool":
|
||||
# sym.name = "bool"
|
||||
|
||||
|
||||
when not defined(SDL_Static):
|
||||
cImport(SDL_Path, recurse = true, dynlib = "SDL_LPath")
|
||||
else:
|
||||
cImport(SDL_Path, recurse = true)
|
||||
124
src/nim_sdl2_image/wrapper.nim
Normal file
124
src/nim_sdl2_image/wrapper.nim
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
import os, strutils
|
||||
import ../nim_sdl2/wrapper
|
||||
import nimterop/[cimport, build]
|
||||
|
||||
const
|
||||
baseDir = currentSourcePath.parentDir().parentDir().parentDir()
|
||||
srcDir = baseDir / "build" / "sdl2_image"
|
||||
|
||||
getHeader(
|
||||
"SDL_image.h",
|
||||
dlurl = "https://www.libsdl.org/projects/SDL_image/release/SDL2_image-2.0.5.tar.gz",
|
||||
outdir = srcDir,
|
||||
altNames = "SDL2_image"
|
||||
)
|
||||
|
||||
static:
|
||||
# cDebug()
|
||||
# cDisableCaching()
|
||||
let contents = readFile(srcDir/"SDL_image.h")
|
||||
let newContents = contents.replace("""#include "SDL.h"
|
||||
#include "SDL_version.h"
|
||||
#include "begin_code.h"""", """
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_version.h>
|
||||
#include <SDL2/begin_code.h>
|
||||
""").
|
||||
replace("""#include "close_code.h"""", "#include <SDL2/close_code.h>")
|
||||
|
||||
writeFile(srcDir/"SDL_image.h", newContents)
|
||||
|
||||
# cOverride:
|
||||
# type
|
||||
|
||||
|
||||
cPlugin:
|
||||
import strutils, nre
|
||||
import sets
|
||||
|
||||
const EVENT_TYPES = toHashSet([
|
||||
"FIRSTEVENT",
|
||||
"QUIT",
|
||||
"APP_TERMINATING",
|
||||
"APP_LOWMEMORY",
|
||||
"APP_WILLENTERBACKGROUND",
|
||||
"APP_DIDENTERBACKGROUND",
|
||||
"APP_WILLENTERFOREGROUND",
|
||||
"APP_DIDENTERFOREGROUND",
|
||||
"DISPLAYEVENT",
|
||||
"WINDOWEVENT",
|
||||
"SYSWMEVENT",
|
||||
"KEYDOWN",
|
||||
"KEYUP",
|
||||
"TEXTEDITING",
|
||||
"TEXTINPUT",
|
||||
"KEYMAPCHANGED",
|
||||
"MOUSEMOTION",
|
||||
"MOUSEBUTTONDOWN",
|
||||
"MOUSEBUTTONUP",
|
||||
"MOUSEWHEEL",
|
||||
"JOYAXISMOTION",
|
||||
"JOYBALLMOTION",
|
||||
"JOYHATMOTION",
|
||||
"JOYBUTTONDOWN",
|
||||
"JOYBUTTONUP",
|
||||
"JOYDEVICEADDED",
|
||||
"JOYDEVICEREMOVED",
|
||||
"CONTROLLERAXISMOTION",
|
||||
"CONTROLLERBUTTONDOWN",
|
||||
"CONTROLLERBUTTONUP",
|
||||
"CONTROLLERDEVICEADDED",
|
||||
"CONTROLLERDEVICEREMOVED",
|
||||
"CONTROLLERDEVICEREMAPPED",
|
||||
"FINGERDOWN",
|
||||
"FINGERUP",
|
||||
"FINGERMOTION",
|
||||
"DOLLARGESTURE",
|
||||
"DOLLARRECORD",
|
||||
"MULTIGESTURE",
|
||||
"CLIPBOARDUPDATE",
|
||||
"DROPFILE",
|
||||
"DROPTEXT",
|
||||
"DROPBEGIN",
|
||||
"DROPCOMPLETE",
|
||||
"AUDIODEVICEADDED",
|
||||
"AUDIODEVICEREMOVED",
|
||||
"SENSORUPDATE",
|
||||
"RENDER_TARGETS_RESET",
|
||||
"RENDER_DEVICE_RESET",
|
||||
"USEREVENT",
|
||||
"LASTEVENT",
|
||||
])
|
||||
|
||||
# Symbol renaming examples
|
||||
proc onSymbol*(sym: var Symbol) {.exportc, dynlib.} =
|
||||
# Get rid of leading and trailing underscores
|
||||
# sym.name = sym.name.strip(chars = {'_'})
|
||||
|
||||
# Remove prefixes or suffixes from procs
|
||||
if sym.name == "__MACOSX__":
|
||||
sym.name = "MACOSX"
|
||||
if sym.kind == nskProc or sym.kind == nskType or sym.kind == nskConst:
|
||||
if sym.name != "_":
|
||||
sym.name = sym.name.replace(re"^_+", "")
|
||||
sym.name = sym.name.replace(re"_+$", "")
|
||||
sym.name = sym.name.replace(re"^SDL_", "")
|
||||
|
||||
if sym.name.startsWith("SDLK_"):
|
||||
sym.name = sym.name.replace("SDLK_", "KEYCODE_")
|
||||
|
||||
if EVENT_TYPES.contains(sym.name):
|
||||
sym.name = "EVENT_" & sym.name
|
||||
|
||||
if sym.name == "ThreadID":
|
||||
sym.name = "CurrentThreadID"
|
||||
if sym.name == "GLContextResetNotification":
|
||||
sym.name = "GLContextResetNotificationEnum"
|
||||
if sym.name == "KeyCode":
|
||||
sym.name = "KeyCodeEnum"
|
||||
|
||||
|
||||
when not defined(SDL_Static):
|
||||
cImport(SDL_image_Path, recurse = false, dynlib = "SDL_image_LPath")
|
||||
else:
|
||||
cImport(SDL_image_Path, recurse = false)
|
||||
131
src/nim_sdl2_mixer/wrapper.nim
Normal file
131
src/nim_sdl2_mixer/wrapper.nim
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
import os, strutils
|
||||
import ../nim_sdl2/wrapper as sdl2_wrapper
|
||||
import nimterop/[cimport, build]
|
||||
|
||||
const
|
||||
baseDir = currentSourcePath.parentDir().parentDir().parentDir()
|
||||
srcDir = baseDir / "build" / "sdl2_mixer"
|
||||
|
||||
getHeader(
|
||||
"SDL_mixer.h",
|
||||
dlurl = "https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-2.0.4.tar.gz",
|
||||
outdir = srcDir,
|
||||
altNames = "SDL2_mixer"
|
||||
)
|
||||
|
||||
static:
|
||||
cDebug()
|
||||
cDisableCaching()
|
||||
let contents = readFile(srcDir/"SDL_mixer.h")
|
||||
let newContents = contents.replace("""#include "SDL_stdinc.h"
|
||||
#include "SDL_rwops.h"
|
||||
#include "SDL_audio.h"
|
||||
#include "SDL_endian.h"
|
||||
#include "SDL_version.h"
|
||||
#include "begin_code.h"
|
||||
""", """
|
||||
#include <SDL2/SDL_stdinc.h>
|
||||
#include <SDL2/SDL_rwops.h>
|
||||
#include <SDL2/SDL_audio.h>
|
||||
#include <SDL2/SDL_endian.h>
|
||||
#include <SDL2/SDL_version.h>
|
||||
#include <SDL2/begin_code.h>
|
||||
""").
|
||||
replace("""#include "close_code.h"""", "#include <SDL2/close_code.h>")
|
||||
|
||||
writeFile(srcDir/"SDL_mixer.h", newContents)
|
||||
|
||||
# cOverride:
|
||||
# type
|
||||
|
||||
|
||||
cPlugin:
|
||||
import strutils, nre
|
||||
import sets
|
||||
|
||||
const EVENT_TYPES = toHashSet([
|
||||
"FIRSTEVENT",
|
||||
"QUIT",
|
||||
"APP_TERMINATING",
|
||||
"APP_LOWMEMORY",
|
||||
"APP_WILLENTERBACKGROUND",
|
||||
"APP_DIDENTERBACKGROUND",
|
||||
"APP_WILLENTERFOREGROUND",
|
||||
"APP_DIDENTERFOREGROUND",
|
||||
"DISPLAYEVENT",
|
||||
"WINDOWEVENT",
|
||||
"SYSWMEVENT",
|
||||
"KEYDOWN",
|
||||
"KEYUP",
|
||||
"TEXTEDITING",
|
||||
"TEXTINPUT",
|
||||
"KEYMAPCHANGED",
|
||||
"MOUSEMOTION",
|
||||
"MOUSEBUTTONDOWN",
|
||||
"MOUSEBUTTONUP",
|
||||
"MOUSEWHEEL",
|
||||
"JOYAXISMOTION",
|
||||
"JOYBALLMOTION",
|
||||
"JOYHATMOTION",
|
||||
"JOYBUTTONDOWN",
|
||||
"JOYBUTTONUP",
|
||||
"JOYDEVICEADDED",
|
||||
"JOYDEVICEREMOVED",
|
||||
"CONTROLLERAXISMOTION",
|
||||
"CONTROLLERBUTTONDOWN",
|
||||
"CONTROLLERBUTTONUP",
|
||||
"CONTROLLERDEVICEADDED",
|
||||
"CONTROLLERDEVICEREMOVED",
|
||||
"CONTROLLERDEVICEREMAPPED",
|
||||
"FINGERDOWN",
|
||||
"FINGERUP",
|
||||
"FINGERMOTION",
|
||||
"DOLLARGESTURE",
|
||||
"DOLLARRECORD",
|
||||
"MULTIGESTURE",
|
||||
"CLIPBOARDUPDATE",
|
||||
"DROPFILE",
|
||||
"DROPTEXT",
|
||||
"DROPBEGIN",
|
||||
"DROPCOMPLETE",
|
||||
"AUDIODEVICEADDED",
|
||||
"AUDIODEVICEREMOVED",
|
||||
"SENSORUPDATE",
|
||||
"RENDER_TARGETS_RESET",
|
||||
"RENDER_DEVICE_RESET",
|
||||
"USEREVENT",
|
||||
"LASTEVENT",
|
||||
])
|
||||
|
||||
# Symbol renaming examples
|
||||
proc onSymbol*(sym: var Symbol) {.exportc, dynlib.} =
|
||||
# Get rid of leading and trailing underscores
|
||||
# sym.name = sym.name.strip(chars = {'_'})
|
||||
|
||||
# Remove prefixes or suffixes from procs
|
||||
if sym.name == "__MACOSX__":
|
||||
sym.name = "MACOSX"
|
||||
if sym.kind == nskProc or sym.kind == nskType or sym.kind == nskConst:
|
||||
if sym.name != "_":
|
||||
sym.name = sym.name.replace(re"^_+", "")
|
||||
sym.name = sym.name.replace(re"_+$", "")
|
||||
sym.name = sym.name.replace(re"^SDL_", "")
|
||||
|
||||
if sym.name.startsWith("SDLK_"):
|
||||
sym.name = sym.name.replace("SDLK_", "KEYCODE_")
|
||||
|
||||
if EVENT_TYPES.contains(sym.name):
|
||||
sym.name = "EVENT_" & sym.name
|
||||
|
||||
if sym.name == "ThreadID":
|
||||
sym.name = "CurrentThreadID"
|
||||
if sym.name == "GLContextResetNotification":
|
||||
sym.name = "GLContextResetNotificationEnum"
|
||||
if sym.name == "KeyCode":
|
||||
sym.name = "KeyCodeEnum"
|
||||
|
||||
|
||||
when not defined(SDL_Static):
|
||||
cImport(SDL_mixer_Path, recurse = false, dynlib = "SDL_mixer_LPath")
|
||||
else:
|
||||
cImport(SDL_mixer_Path, recurse = false)
|
||||
7
src/sdl2.nim
Normal file
7
src/sdl2.nim
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import nim_sdl2 / wrapper as sdl2_wrapper
|
||||
import nim_sdl2_image / wrapper as sdl2_image_wrapper
|
||||
import nim_sdl2_mixer / wrapper as sdl2_mixer_wrapper
|
||||
|
||||
export sdl2_wrapper
|
||||
export sdl2_image_wrapper
|
||||
export sdl2_mixer_wrapper
|
||||
Loading…
Add table
Add a link
Reference in a new issue