Skip to content

Instantly share code, notes, and snippets.

@awr1

awr1/app.nim Secret

Created September 20, 2020 10:18
Show Gist options
  • Save awr1/93470331d4ec0626930d2e6b1433b48c to your computer and use it in GitHub Desktop.
Save awr1/93470331d4ec0626930d2e6b1433b48c to your computer and use it in GitHub Desktop.
# compile with
# nim c --app:dll -o:app.dll app.nim
# nim c --app:exe -o:app.exe app.nim
# then run app.exe
when compileOption("app", "exe"):
type App = ptr object
{.pragma: appImport, importc, nimcall, dynlib: "app".}
proc newApp() :App {.appImport.}
proc run(app :App) {.appImport.}
var app = newApp()
app.run
elif compileOption("app", "dll"):
type App = ptr object
{.pragma: appExport, exportc, nimcall, dynlib.}
proc newApp() :App {.appExport.} = nil
proc run(app :App) {.appExport.} = echo("run() from DLL")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment