Initial template
This commit is contained in:
parent
6f9b2523e7
commit
c070567f0c
7 changed files with 102 additions and 0 deletions
1
examples/nim.cfg
Normal file
1
examples/nim.cfg
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
--path:"../src/"
|
||||||
1
nim.cfg
Normal file
1
nim.cfg
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
-d:NimteropTemplate_SetVer="M.M.V" -d:NimteropTemplate_DL -d:NimteropTemplate_Static
|
||||||
13
nimterop_template.nimble
Normal file
13
nimterop_template.nimble
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
# Package
|
||||||
|
|
||||||
|
version = "0.1.0"
|
||||||
|
author = "Joey Yakimowich-Payne"
|
||||||
|
description = "Nimterop template"
|
||||||
|
license = "MIT"
|
||||||
|
srcDir = "src"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Dependencies
|
||||||
|
|
||||||
|
requires "nim >= 1.0.6", "nimterop#head"
|
||||||
3
src/nimterop_template.nim
Normal file
3
src/nimterop_template.nim
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
import nimterop_template/nimterop_template
|
||||||
|
|
||||||
|
export nimterop_template
|
||||||
44
src/nimterop_template/cleansymbols.nim
Normal file
44
src/nimterop_template/cleansymbols.nim
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
import macros, nimterop / plugin
|
||||||
|
import strutils, regex
|
||||||
|
import sets
|
||||||
|
|
||||||
|
proc firstLetterLower(m: RegexMatch, s: string): string =
|
||||||
|
if m.groupsCount > 0 and m.group(0).len > 0:
|
||||||
|
return s[m.group(0)[0]].toLowerAscii
|
||||||
|
|
||||||
|
proc camelCase(m: RegexMatch, s: string): string =
|
||||||
|
if m.groupsCount > 0 and m.group(0).len > 0:
|
||||||
|
return s[m.group(0)[0]].toUpperAscii
|
||||||
|
|
||||||
|
proc nothing(m: RegexMatch, s: string): string =
|
||||||
|
if m.groupsCount > 0 and m.group(0).len > 0:
|
||||||
|
return s[m.group(0)[0]]
|
||||||
|
|
||||||
|
const replacements = [
|
||||||
|
re"^PREFIX_(.)",
|
||||||
|
]
|
||||||
|
|
||||||
|
const underscoreReg = re"_(.)"
|
||||||
|
|
||||||
|
# Symbol renaming examples
|
||||||
|
proc onSymbol*(sym: var Symbol) {.exportc, dynlib.} =
|
||||||
|
if sym.kind == nskProc or sym.kind == nskType or sym.kind == nskConst:
|
||||||
|
if sym.name != "_":
|
||||||
|
sym.name = sym.name.strip(chars={'_'}).replace("__", "_")
|
||||||
|
|
||||||
|
for rep in replacements:
|
||||||
|
if sym.kind == nskProc:
|
||||||
|
try:
|
||||||
|
sym.name = sym.name.replace(rep, firstLetterLower)
|
||||||
|
except:
|
||||||
|
discard
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
sym.name = sym.name.replace(rep, nothing)
|
||||||
|
except:
|
||||||
|
discard
|
||||||
|
|
||||||
|
if sym.kind == nskField:
|
||||||
|
sym.name = sym.name.replace(underscoreReg, camelCase)
|
||||||
|
if sym.name == "type":
|
||||||
|
sym.name = "kind"
|
||||||
39
src/nimterop_template/nimterop_template.nim
Normal file
39
src/nimterop_template/nimterop_template.nim
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
import os, strutils, strformat
|
||||||
|
import nimterop/[cimport, build]
|
||||||
|
|
||||||
|
const
|
||||||
|
SDLCacheDir* = currentSourcePath.parentDir().parentDir() / "build" #getProjectCacheDir("nimsdl2")
|
||||||
|
baseDir = SDLCacheDir
|
||||||
|
srcDir = baseDir / "sdl2"
|
||||||
|
buildDir = srcDir / "buildcache"
|
||||||
|
symbolPluginPath = currentSourcePath.parentDir() / "cleansymbols.nim"
|
||||||
|
|
||||||
|
getHeader(
|
||||||
|
"template.h",
|
||||||
|
dlurl = "https://download.com/template-$1.tar.gz",
|
||||||
|
outdir = srcDir,
|
||||||
|
cmakeFlags = "-F flag",
|
||||||
|
conFlags = "-F flag"
|
||||||
|
)
|
||||||
|
|
||||||
|
static:
|
||||||
|
discard
|
||||||
|
# gitPull("https://github.com/lib/project", outdir=srcDir, plist="""
|
||||||
|
# src/*.h
|
||||||
|
# src/*.c
|
||||||
|
# """, checkout = "1f9c8864fc556a1be4d4bf1d6bfe20cde25734b4")
|
||||||
|
# cSkipSymbol @[]
|
||||||
|
# cDebug()
|
||||||
|
# cDisableCaching()
|
||||||
|
# let contents = readFile(srcDir/"src"/"dynapi"/"SDL_dynapi_procs.h")
|
||||||
|
# writeFile(srcDir/"src"/"dynapi"/"SDL_dynapi_procs.c", contents
|
||||||
|
|
||||||
|
cOverride:
|
||||||
|
discard
|
||||||
|
|
||||||
|
cPluginPath(symbolPluginPath)
|
||||||
|
|
||||||
|
when defined(NimteropTemplate_Static):
|
||||||
|
cImport(NimteropTemplate_Path, recurse = true, flags = "-f=ast2 -E__,_ -F__,_")
|
||||||
|
else:
|
||||||
|
cImport(NimteropTemplate_Path, recurse = true, dynlib = "NimteropTemplate_LPath", flags = "-f=ast2 -E__,_ -F__,_")
|
||||||
1
tests/config.nims
Normal file
1
tests/config.nims
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
switch("path", "$projectDir/../src")
|
||||||
Loading…
Add table
Add a link
Reference in a new issue