Skip to content

Commit

Permalink
add header field
Browse files Browse the repository at this point in the history
  • Loading branch information
planetis-m committed Oct 7, 2024
1 parent f740ee4 commit 9cdacfa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
17 changes: 10 additions & 7 deletions tools/newdsl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import common
type
Builder* = object
nesting: int
header: string
outp: Stream

proc openBuilder*(filename: string): Builder =
Builder(outp: openFileStream(filename, fmWrite), nesting: 0)
proc openBuilder*(filename, header: string): Builder =
Builder(outp: openFileStream(filename, fmWrite), header: header, nesting: 0)

proc openBuilder*(sizeHint: int): Builder =
Builder(outp: newStringStream(newStringOfCap(sizeHint)), nesting: 0)
proc openBuilder*(sizeHint: int; header: string): Builder =
Builder(outp: newStringStream(newStringOfCap(sizeHint)), header: header, nesting: 0)

proc close*(b: Builder) =
if b.outp != nil:
Expand Down Expand Up @@ -103,7 +104,7 @@ proc generateObject*(b: var Builder, obj: StructInfo) =
b.addRaw ": "
b.addStrLit "rl" & obj.name
b.addRaw ", header: "
b.addStrLit "raylib.h"
b.addStrLit b.header
if isCompleteStruct in obj.flags:
b.addRaw ", completeStruct"
b.addRaw ", bycopy.} = object"
Expand Down Expand Up @@ -196,7 +197,7 @@ proc generateWrappedProc*(b: var Builder, fnc: FunctionInfo) =
elif isVarParam in param.flags:
b.addRaw "addr "
if isArrayLength in param.flags:
b.addRaw param.baseType
b.addRaw param.baseType # stores array name
b.addRaw ".len."
b.addRaw param.`type`
else:
Expand Down Expand Up @@ -239,7 +240,9 @@ proc genBindings*(b: var Builder; ctx: ApiContext;
b.addRaw("\n\n")
b.addRaw afterObjects
# Generate procs
b.addRaw "\n{.push callconv: cdecl, header: \"raylib.h\".}"
b.addRaw "\n{.push callconv: cdecl, header: "
b.addStrLit b.header
b.addRaw ".}"
for fnc in items(ctx.api.functions):
generateProc(b, fnc)
# b.addNewLine()
Expand Down
4 changes: 2 additions & 2 deletions tools/raylib_gen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ proc preprocessFunctions(ctx: var ApiContext) =
param.baseType = baseType
param.flags.incl isOpenArray
fnc.params[i+1].flags.incl isArrayLength
fnc.params[i+1].baseType = param.name # Needs cleanup
fnc.params[i+1].baseType = param.name # stores array name
autoWrap = true
if paramType.startsWith("var "):
param.flags.incl isVarParam
Expand Down Expand Up @@ -679,7 +679,7 @@ proc preprocessApi(ctx: var ApiContext) =
preprocessFunctions(ctx)

proc generateOutput(ctx: ApiContext) =
var b = openBuilder(outputname)
var b = openBuilder(outputname, header = "raylib.h")
genBindings(b, ctx,
moduleHeader = raylibHeader, afterEnums = bitsetsHelperAndDuplicateValues,
afterObjects = opaqueStructs & callbacksAndColors, afterFuncs = destructorHooks & arrayAccessors,
Expand Down

0 comments on commit 9cdacfa

Please sign in to comment.