Initial template

This commit is contained in:
Joey Yakimowich-Payne 2020-04-26 16:17:28 -06:00
commit c070567f0c
7 changed files with 102 additions and 0 deletions

1
examples/nim.cfg Normal file
View file

@ -0,0 +1 @@
--path:"../src/"

1
nim.cfg Normal file
View file

@ -0,0 +1 @@
-d:NimteropTemplate_SetVer="M.M.V" -d:NimteropTemplate_DL -d:NimteropTemplate_Static

13
nimterop_template.nimble Normal file
View 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"

View file

@ -0,0 +1,3 @@
import nimterop_template/nimterop_template
export nimterop_template

View 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"

View 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
View file

@ -0,0 +1 @@
switch("path", "$projectDir/../src")