Merge branch 'master' into vm2
Conflicts: compiler/sem.nim
This commit is contained in:
commit
5eba93d584
135 changed files with 2221 additions and 90065 deletions
|
|
@ -713,7 +713,6 @@ type
|
||||||
# -1 means that the size is unkwown
|
# -1 means that the size is unkwown
|
||||||
align*: int # the type's alignment requirements
|
align*: int # the type's alignment requirements
|
||||||
loc*: TLoc
|
loc*: TLoc
|
||||||
testeeName*: PIdent # the test variable in user-defined type classes
|
|
||||||
|
|
||||||
TPair*{.final.} = object
|
TPair*{.final.} = object
|
||||||
key*, val*: PObject
|
key*, val*: PObject
|
||||||
|
|
@ -1089,7 +1088,6 @@ proc assignType(dest, src: PType) =
|
||||||
dest.size = src.size
|
dest.size = src.size
|
||||||
dest.align = src.align
|
dest.align = src.align
|
||||||
dest.destructor = src.destructor
|
dest.destructor = src.destructor
|
||||||
dest.testeeName = src.testeeName
|
|
||||||
# this fixes 'type TLock = TSysLock':
|
# this fixes 'type TLock = TSysLock':
|
||||||
if src.sym != nil:
|
if src.sym != nil:
|
||||||
if dest.sym != nil:
|
if dest.sym != nil:
|
||||||
|
|
|
||||||
|
|
@ -240,6 +240,7 @@ proc genGenericAsgn(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
||||||
if needToCopy notin flags or
|
if needToCopy notin flags or
|
||||||
tfShallow in skipTypes(dest.t, abstractVarRange).flags:
|
tfShallow in skipTypes(dest.t, abstractVarRange).flags:
|
||||||
if dest.s == OnStack or not usesNativeGC():
|
if dest.s == OnStack or not usesNativeGC():
|
||||||
|
useStringh(p.module)
|
||||||
linefmt(p, cpsStmts,
|
linefmt(p, cpsStmts,
|
||||||
"memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($3));$n",
|
"memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($3));$n",
|
||||||
addrLoc(dest), addrLoc(src), rdLoc(dest))
|
addrLoc(dest), addrLoc(src), rdLoc(dest))
|
||||||
|
|
@ -316,6 +317,7 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
||||||
if needsComplexAssignment(dest.t):
|
if needsComplexAssignment(dest.t):
|
||||||
genGenericAsgn(p, dest, src, flags)
|
genGenericAsgn(p, dest, src, flags)
|
||||||
else:
|
else:
|
||||||
|
useStringh(p.module)
|
||||||
linefmt(p, cpsStmts,
|
linefmt(p, cpsStmts,
|
||||||
"memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($1));$n",
|
"memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($1));$n",
|
||||||
rdLoc(dest), rdLoc(src))
|
rdLoc(dest), rdLoc(src))
|
||||||
|
|
@ -327,11 +329,13 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
||||||
"#genericAssignOpenArray((void*)$1, (void*)$2, $1Len0, $3);$n",
|
"#genericAssignOpenArray((void*)$1, (void*)$2, $1Len0, $3);$n",
|
||||||
addrLoc(dest), addrLoc(src), genTypeInfo(p.module, dest.t))
|
addrLoc(dest), addrLoc(src), genTypeInfo(p.module, dest.t))
|
||||||
else:
|
else:
|
||||||
|
useStringh(p.module)
|
||||||
linefmt(p, cpsStmts,
|
linefmt(p, cpsStmts,
|
||||||
"memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($1[0])*$1Len0);$n",
|
"memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($1[0])*$1Len0);$n",
|
||||||
rdLoc(dest), rdLoc(src))
|
rdLoc(dest), rdLoc(src))
|
||||||
of tySet:
|
of tySet:
|
||||||
if mapType(ty) == ctArray:
|
if mapType(ty) == ctArray:
|
||||||
|
useStringh(p.module)
|
||||||
linefmt(p, cpsStmts, "memcpy((void*)$1, (NIM_CONST void*)$2, $3);$n",
|
linefmt(p, cpsStmts, "memcpy((void*)$1, (NIM_CONST void*)$2, $3);$n",
|
||||||
rdLoc(dest), rdLoc(src), toRope(getSize(dest.t)))
|
rdLoc(dest), rdLoc(src), toRope(getSize(dest.t)))
|
||||||
else:
|
else:
|
||||||
|
|
@ -1361,6 +1365,7 @@ proc genSetOp(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
|
||||||
lineF(p, cpsStmts, lookupOpr[op],
|
lineF(p, cpsStmts, lookupOpr[op],
|
||||||
[rdLoc(i), toRope(size), rdLoc(d), rdLoc(a), rdLoc(b)])
|
[rdLoc(i), toRope(size), rdLoc(d), rdLoc(a), rdLoc(b)])
|
||||||
of mEqSet:
|
of mEqSet:
|
||||||
|
useStringh(p.module)
|
||||||
binaryExprChar(p, e, d, "(memcmp($1, $2, " & $(size) & ")==0)")
|
binaryExprChar(p, e, d, "(memcmp($1, $2, " & $(size) & ")==0)")
|
||||||
of mMulSet, mPlusSet, mMinusSet, mSymDiffSet:
|
of mMulSet, mPlusSet, mMinusSet, mSymDiffSet:
|
||||||
# we inline the simple for loop for better code generation:
|
# we inline the simple for loop for better code generation:
|
||||||
|
|
@ -1612,6 +1617,7 @@ proc genSetConstr(p: BProc, e: PNode, d: var TLoc) =
|
||||||
if d.k == locNone: getTemp(p, e.typ, d)
|
if d.k == locNone: getTemp(p, e.typ, d)
|
||||||
if getSize(e.typ) > 8:
|
if getSize(e.typ) > 8:
|
||||||
# big set:
|
# big set:
|
||||||
|
useStringh(p.module)
|
||||||
lineF(p, cpsStmts, "memset($1, 0, sizeof($1));$n", [rdLoc(d)])
|
lineF(p, cpsStmts, "memset($1, 0, sizeof($1));$n", [rdLoc(d)])
|
||||||
for i in countup(0, sonsLen(e) - 1):
|
for i in countup(0, sonsLen(e) - 1):
|
||||||
if e.sons[i].kind == nkRange:
|
if e.sons[i].kind == nkRange:
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,11 @@ proc isSimpleConst(typ: PType): bool =
|
||||||
{tyTuple, tyObject, tyArray, tyArrayConstr, tySet, tySequence} and not
|
{tyTuple, tyObject, tyArray, tyArrayConstr, tySet, tySequence} and not
|
||||||
(t.kind == tyProc and t.callConv == ccClosure)
|
(t.kind == tyProc and t.callConv == ccClosure)
|
||||||
|
|
||||||
|
proc useStringh(m: BModule) =
|
||||||
|
if not m.includesStringh:
|
||||||
|
m.includesStringh = true
|
||||||
|
discard lists.IncludeStr(m.headerFiles, "<string.h>")
|
||||||
|
|
||||||
proc useHeader(m: BModule, sym: PSym) =
|
proc useHeader(m: BModule, sym: PSym) =
|
||||||
if lfHeader in sym.loc.Flags:
|
if lfHeader in sym.loc.Flags:
|
||||||
assert(sym.annex != nil)
|
assert(sym.annex != nil)
|
||||||
|
|
@ -358,19 +363,24 @@ proc resetLoc(p: BProc, loc: var TLoc) =
|
||||||
# field, so disabling this should be safe:
|
# field, so disabling this should be safe:
|
||||||
genObjectInit(p, cpsStmts, loc.t, loc, true)
|
genObjectInit(p, cpsStmts, loc.t, loc, true)
|
||||||
else:
|
else:
|
||||||
|
useStringh(p.module)
|
||||||
linefmt(p, cpsStmts, "memset((void*)$1, 0, sizeof($2));$n",
|
linefmt(p, cpsStmts, "memset((void*)$1, 0, sizeof($2));$n",
|
||||||
addrLoc(loc), rdLoc(loc))
|
addrLoc(loc), rdLoc(loc))
|
||||||
# XXX: We can be extra clever here and call memset only
|
# XXX: We can be extra clever here and call memset only
|
||||||
# on the bytes following the m_type field?
|
# on the bytes following the m_type field?
|
||||||
genObjectInit(p, cpsStmts, loc.t, loc, true)
|
genObjectInit(p, cpsStmts, loc.t, loc, true)
|
||||||
|
|
||||||
proc constructLoc(p: BProc, loc: TLoc, section = cpsStmts) =
|
proc constructLoc(p: BProc, loc: TLoc, isTemp = false) =
|
||||||
if not isComplexValueType(skipTypes(loc.t, abstractRange)):
|
if not isComplexValueType(skipTypes(loc.t, abstractRange)):
|
||||||
linefmt(p, section, "$1 = 0;$n", rdLoc(loc))
|
linefmt(p, cpsStmts, "$1 = 0;$n", rdLoc(loc))
|
||||||
else:
|
else:
|
||||||
linefmt(p, section, "memset((void*)$1, 0, sizeof($2));$n",
|
if not isTemp or containsGarbageCollectedRef(loc.t):
|
||||||
addrLoc(loc), rdLoc(loc))
|
# don't use memset for temporary values for performance if we can
|
||||||
genObjectInit(p, section, loc.t, loc, true)
|
# avoid it:
|
||||||
|
useStringh(p.module)
|
||||||
|
linefmt(p, cpsStmts, "memset((void*)$1, 0, sizeof($2));$n",
|
||||||
|
addrLoc(loc), rdLoc(loc))
|
||||||
|
genObjectInit(p, cpsStmts, loc.t, loc, true)
|
||||||
|
|
||||||
proc initLocalVar(p: BProc, v: PSym, immediateAsgn: bool) =
|
proc initLocalVar(p: BProc, v: PSym, immediateAsgn: bool) =
|
||||||
if sfNoInit notin v.flags:
|
if sfNoInit notin v.flags:
|
||||||
|
|
@ -396,7 +406,7 @@ proc getTemp(p: BProc, t: PType, result: var TLoc) =
|
||||||
result.t = getUniqueType(t)
|
result.t = getUniqueType(t)
|
||||||
result.s = OnStack
|
result.s = OnStack
|
||||||
result.flags = {}
|
result.flags = {}
|
||||||
constructLoc(p, result)
|
constructLoc(p, result, isTemp=true)
|
||||||
|
|
||||||
proc keepAlive(p: BProc, toKeepAlive: TLoc) =
|
proc keepAlive(p: BProc, toKeepAlive: TLoc) =
|
||||||
when false:
|
when false:
|
||||||
|
|
@ -418,6 +428,7 @@ proc keepAlive(p: BProc, toKeepAlive: TLoc) =
|
||||||
if not isComplexValueType(skipTypes(toKeepAlive.t, abstractVarRange)):
|
if not isComplexValueType(skipTypes(toKeepAlive.t, abstractVarRange)):
|
||||||
linefmt(p, cpsStmts, "$1 = $2;$n", rdLoc(result), rdLoc(toKeepAlive))
|
linefmt(p, cpsStmts, "$1 = $2;$n", rdLoc(result), rdLoc(toKeepAlive))
|
||||||
else:
|
else:
|
||||||
|
useStringh(p.module)
|
||||||
linefmt(p, cpsStmts,
|
linefmt(p, cpsStmts,
|
||||||
"memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($3));$n",
|
"memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($3));$n",
|
||||||
addrLoc(result), addrLoc(toKeepAlive), rdLoc(result))
|
addrLoc(result), addrLoc(toKeepAlive), rdLoc(result))
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,7 @@ type
|
||||||
FrameDeclared*: bool # hack for ROD support so that we don't declare
|
FrameDeclared*: bool # hack for ROD support so that we don't declare
|
||||||
# a frame var twice in an init proc
|
# a frame var twice in an init proc
|
||||||
isHeaderFile*: bool # C source file is the header file
|
isHeaderFile*: bool # C source file is the header file
|
||||||
|
includesStringh*: bool # C source file already includes ``<string.h>``
|
||||||
cfilename*: string # filename of the module (including path,
|
cfilename*: string # filename of the module (including path,
|
||||||
# without extension)
|
# without extension)
|
||||||
typeCache*: TIdTable # cache the generated types
|
typeCache*: TIdTable # cache the generated types
|
||||||
|
|
|
||||||
|
|
@ -583,7 +583,7 @@ proc CallCCompiler*(projectfile: string) =
|
||||||
else:
|
else:
|
||||||
rawMessage(errGenerated, " execution of an external program failed; " &
|
rawMessage(errGenerated, " execution of an external program failed; " &
|
||||||
"rerun with --parallelBuild:1 to see the error message")
|
"rerun with --parallelBuild:1 to see the error message")
|
||||||
if optNoLinking notin gGlobalOptions and cmds.len > 0:
|
if optNoLinking notin gGlobalOptions:
|
||||||
# call the linker:
|
# call the linker:
|
||||||
var it = PStrEntry(toLink.head)
|
var it = PStrEntry(toLink.head)
|
||||||
var objfiles = ""
|
var objfiles = ""
|
||||||
|
|
|
||||||
|
|
@ -91,13 +91,17 @@ proc Remove*(list: var TLinkedList, entry: PListEntry) =
|
||||||
if entry.prev != nil: entry.prev.next = entry.next
|
if entry.prev != nil: entry.prev.next = entry.next
|
||||||
|
|
||||||
proc bringToFront*(list: var TLinkedList, entry: PListEntry) =
|
proc bringToFront*(list: var TLinkedList, entry: PListEntry) =
|
||||||
if entry == list.head: return
|
when true:
|
||||||
if entry == list.tail: list.tail = entry.prev
|
list.remove entry
|
||||||
if entry.next != nil: entry.next.prev = entry.prev
|
list.prepend entry
|
||||||
if entry.prev != nil: entry.prev.next = entry.next
|
else:
|
||||||
entry.prev = nil
|
if entry == list.head: return
|
||||||
entry.next = list.head
|
if entry == list.tail: list.tail = entry.prev
|
||||||
list.head = entry
|
if entry.next != nil: entry.next.prev = entry.prev
|
||||||
|
if entry.prev != nil: entry.prev.next = entry.next
|
||||||
|
entry.prev = nil
|
||||||
|
entry.next = list.head
|
||||||
|
list.head = entry
|
||||||
|
|
||||||
proc ExcludeStr*(list: var TLinkedList, data: string) =
|
proc ExcludeStr*(list: var TLinkedList, data: string) =
|
||||||
var it = list.head
|
var it = list.head
|
||||||
|
|
|
||||||
|
|
@ -437,6 +437,13 @@ type
|
||||||
line*, col*: int16
|
line*, col*: int16
|
||||||
fileIndex*: int32
|
fileIndex*: int32
|
||||||
|
|
||||||
|
TErrorOutput* = enum
|
||||||
|
eStdOut
|
||||||
|
eStdErr
|
||||||
|
eInMemory
|
||||||
|
|
||||||
|
TErrorOutputs* = set[TErrorOutput]
|
||||||
|
|
||||||
ERecoverableError* = object of EInvalidValue
|
ERecoverableError* = object of EInvalidValue
|
||||||
ESuggestDone* = object of EBase
|
ESuggestDone* = object of EBase
|
||||||
|
|
||||||
|
|
@ -534,13 +541,27 @@ var
|
||||||
gHintCounter*: int = 0
|
gHintCounter*: int = 0
|
||||||
gWarnCounter*: int = 0
|
gWarnCounter*: int = 0
|
||||||
gErrorMax*: int = 1 # stop after gErrorMax errors
|
gErrorMax*: int = 1 # stop after gErrorMax errors
|
||||||
gSilence*: int # == 0 if we produce any output at all
|
|
||||||
|
|
||||||
when useCaas:
|
when useCaas:
|
||||||
var stdoutSocket*: TSocket
|
var stdoutSocket*: TSocket
|
||||||
|
|
||||||
|
proc UnknownLineInfo*(): TLineInfo =
|
||||||
|
result.line = int16(-1)
|
||||||
|
result.col = int16(-1)
|
||||||
|
result.fileIndex = -1
|
||||||
|
|
||||||
|
var
|
||||||
|
msgContext: seq[TLineInfo] = @[]
|
||||||
|
lastError = UnknownLineInfo()
|
||||||
|
bufferedMsgs*: seq[string]
|
||||||
|
|
||||||
|
errorOutputs* = {eStdOut, eStdErr}
|
||||||
|
|
||||||
|
proc clearBufferedMsgs* =
|
||||||
|
bufferedMsgs = nil
|
||||||
|
|
||||||
proc SuggestWriteln*(s: string) =
|
proc SuggestWriteln*(s: string) =
|
||||||
if gSilence == 0:
|
if eStdOut in errorOutputs:
|
||||||
when useCaas:
|
when useCaas:
|
||||||
if isNil(stdoutSocket): Writeln(stdout, s)
|
if isNil(stdoutSocket): Writeln(stdout, s)
|
||||||
else:
|
else:
|
||||||
|
|
@ -549,6 +570,9 @@ proc SuggestWriteln*(s: string) =
|
||||||
else:
|
else:
|
||||||
Writeln(stdout, s)
|
Writeln(stdout, s)
|
||||||
|
|
||||||
|
if eInMemory in errorOutputs:
|
||||||
|
bufferedMsgs.safeAdd(s)
|
||||||
|
|
||||||
proc SuggestQuit*() =
|
proc SuggestQuit*() =
|
||||||
if not isServing:
|
if not isServing:
|
||||||
quit(0)
|
quit(0)
|
||||||
|
|
@ -570,14 +594,6 @@ const
|
||||||
RawWarningFormat* = "Warning: $1"
|
RawWarningFormat* = "Warning: $1"
|
||||||
RawHintFormat* = "Hint: $1"
|
RawHintFormat* = "Hint: $1"
|
||||||
|
|
||||||
proc UnknownLineInfo*(): TLineInfo =
|
|
||||||
result.line = int16(-1)
|
|
||||||
result.col = int16(-1)
|
|
||||||
result.fileIndex = -1
|
|
||||||
|
|
||||||
var
|
|
||||||
msgContext: seq[TLineInfo] = @[]
|
|
||||||
|
|
||||||
proc getInfoContextLen*(): int = return msgContext.len
|
proc getInfoContextLen*(): int = return msgContext.len
|
||||||
proc setInfoContextLen*(L: int) = setLen(msgContext, L)
|
proc setInfoContextLen*(L: int) = setLen(msgContext, L)
|
||||||
|
|
||||||
|
|
@ -642,14 +658,18 @@ proc addCheckpoint*(filename: string, line: int) =
|
||||||
|
|
||||||
proc OutWriteln*(s: string) =
|
proc OutWriteln*(s: string) =
|
||||||
## Writes to stdout. Always.
|
## Writes to stdout. Always.
|
||||||
if gSilence == 0: Writeln(stdout, s)
|
if eStdOut in errorOutputs: Writeln(stdout, s)
|
||||||
|
|
||||||
proc MsgWriteln*(s: string) =
|
proc MsgWriteln*(s: string) =
|
||||||
## Writes to stdout. If --stdout option is given, writes to stderr instead.
|
## Writes to stdout. If --stdout option is given, writes to stderr instead.
|
||||||
if gSilence == 0:
|
if gCmd == cmdIdeTools and optCDebug notin gGlobalOptions: return
|
||||||
if gCmd == cmdIdeTools and optCDebug notin gGlobalOptions: return
|
|
||||||
if optStdout in gGlobalOptions: Writeln(stderr, s)
|
if optStdout in gGlobalOptions:
|
||||||
else: Writeln(stdout, s)
|
if eStdErr in errorOutputs: Writeln(stderr, s)
|
||||||
|
else:
|
||||||
|
if eStdOut in errorOutputs: Writeln(stdout, s)
|
||||||
|
|
||||||
|
if eInMemory in errorOutputs: bufferedMsgs.safeAdd(s)
|
||||||
|
|
||||||
proc coordToStr(coord: int): string =
|
proc coordToStr(coord: int): string =
|
||||||
if coord == -1: result = "???"
|
if coord == -1: result = "???"
|
||||||
|
|
@ -736,9 +756,6 @@ proc rawMessage*(msg: TMsgKind, args: openarray[string]) =
|
||||||
proc rawMessage*(msg: TMsgKind, arg: string) =
|
proc rawMessage*(msg: TMsgKind, arg: string) =
|
||||||
rawMessage(msg, [arg])
|
rawMessage(msg, [arg])
|
||||||
|
|
||||||
var
|
|
||||||
lastError = UnknownLineInfo()
|
|
||||||
|
|
||||||
proc writeSurroundingSrc(info: TLineInfo) =
|
proc writeSurroundingSrc(info: TLineInfo) =
|
||||||
const indent = " "
|
const indent = " "
|
||||||
MsgWriteln(indent & info.sourceLine.ropeToStr)
|
MsgWriteln(indent & info.sourceLine.ropeToStr)
|
||||||
|
|
|
||||||
|
|
@ -243,11 +243,6 @@ proc LoadConfigs*(cfg: string) =
|
||||||
readConfigFile(pd / cfg)
|
readConfigFile(pd / cfg)
|
||||||
|
|
||||||
if gProjectName.len != 0:
|
if gProjectName.len != 0:
|
||||||
var conffile = changeFileExt(gProjectFull, "cfg")
|
|
||||||
if conffile != pd / cfg and existsFile(conffile):
|
|
||||||
readConfigFile(conffile)
|
|
||||||
rawMessage(warnConfigDeprecated, conffile)
|
|
||||||
|
|
||||||
# new project wide config file:
|
# new project wide config file:
|
||||||
readConfigFile(changeFileExt(gProjectFull, "nimrod.cfg"))
|
readConfigFile(changeFileExt(gProjectFull, "nimrod.cfg"))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1624,10 +1624,23 @@ proc parseObject(p: var TParser): PNode =
|
||||||
return
|
return
|
||||||
addSon(result, parseObjectPart(p))
|
addSon(result, parseObjectPart(p))
|
||||||
|
|
||||||
|
proc parseTypeClassParam(p: var TParser): PNode =
|
||||||
|
if p.tok.tokType == tkVar:
|
||||||
|
getTok(p)
|
||||||
|
result = newNode(nkVarTy)
|
||||||
|
result.addSon(p.parseSymbol)
|
||||||
|
else:
|
||||||
|
result = p.parseSymbol
|
||||||
|
|
||||||
proc parseTypeClass(p: var TParser): PNode =
|
proc parseTypeClass(p: var TParser): PNode =
|
||||||
result = newNodeP(nkTypeClassTy, p)
|
result = newNodeP(nkTypeClassTy, p)
|
||||||
getTok(p)
|
getTok(p)
|
||||||
addSon(result, p.parseSymbol)
|
var args = newNode(nkArgList)
|
||||||
|
addSon(result, args)
|
||||||
|
addSon(args, p.parseTypeClassParam)
|
||||||
|
while p.tok.TokType == tkComma:
|
||||||
|
getTok(p)
|
||||||
|
addSon(args, p.parseTypeClassParam)
|
||||||
if p.tok.tokType == tkCurlyDotLe and p.validInd:
|
if p.tok.tokType == tkCurlyDotLe and p.validInd:
|
||||||
addSon(result, parsePragma(p))
|
addSon(result, parsePragma(p))
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,8 @@ proc semParamList(c: PContext, n, genericParams: PNode, s: PSym)
|
||||||
proc addParams(c: PContext, n: PNode, kind: TSymKind)
|
proc addParams(c: PContext, n: PNode, kind: TSymKind)
|
||||||
proc maybeAddResult(c: PContext, s: PSym, n: PNode)
|
proc maybeAddResult(c: PContext, s: PSym, n: PNode)
|
||||||
proc instGenericContainer(c: PContext, n: PNode, header: PType): PType
|
proc instGenericContainer(c: PContext, n: PNode, header: PType): PType
|
||||||
proc tryExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode
|
proc tryExpr(c: PContext, n: PNode,
|
||||||
|
flags: TExprFlags = {}, bufferErrors = false): PNode
|
||||||
proc fixImmediateParams(n: PNode): PNode
|
proc fixImmediateParams(n: PNode): PNode
|
||||||
proc activate(c: PContext, n: PNode)
|
proc activate(c: PContext, n: PNode)
|
||||||
proc semQuoteAst(c: PContext, n: PNode): PNode
|
proc semQuoteAst(c: PContext, n: PNode): PNode
|
||||||
|
|
@ -89,6 +90,24 @@ proc commonType*(x, y: PType): PType =
|
||||||
let idx = ord(b.kind in {tyArray, tyArrayConstr})
|
let idx = ord(b.kind in {tyArray, tyArrayConstr})
|
||||||
if a.sons[idx].kind == tyEmpty: return y
|
if a.sons[idx].kind == tyEmpty: return y
|
||||||
#elif b.sons[idx].kind == tyEmpty: return x
|
#elif b.sons[idx].kind == tyEmpty: return x
|
||||||
|
elif a.kind == tyRange and b.kind == tyRange:
|
||||||
|
# consider: (range[0..3], range[0..4]) here. We should make that
|
||||||
|
# range[0..4]. But then why is (range[0..4], 6) not range[0..6]?
|
||||||
|
# But then why is (2,4) not range[2..4]? But I think this would break
|
||||||
|
# too much code. So ... it's the same range or the base type. This means
|
||||||
|
# type(if b: 0 else 1) == int and not range[0..1]. For now. In the long
|
||||||
|
# run people expect ranges to work properly within a tuple.
|
||||||
|
if not sameType(a, b):
|
||||||
|
result = skipTypes(a, {tyRange}).skipIntLit
|
||||||
|
when false:
|
||||||
|
if a.kind != tyRange and b.kind == tyRange:
|
||||||
|
# XXX This really needs a better solution, but a proper fix now breaks
|
||||||
|
# code.
|
||||||
|
result = a #.skipIntLit
|
||||||
|
elif a.kind == tyRange and b.kind != tyRange:
|
||||||
|
result = b #.skipIntLit
|
||||||
|
elif a.kind in IntegralTypes and a.n != nil:
|
||||||
|
result = a #.skipIntLit
|
||||||
else:
|
else:
|
||||||
var k = tyNone
|
var k = tyNone
|
||||||
if a.kind in {tyRef, tyPtr}:
|
if a.kind in {tyRef, tyPtr}:
|
||||||
|
|
@ -102,7 +121,7 @@ proc commonType*(x, y: PType): PType =
|
||||||
if result.isNil: return x
|
if result.isNil: return x
|
||||||
if k != tyNone:
|
if k != tyNone:
|
||||||
let r = result
|
let r = result
|
||||||
result = NewType(k, r.owner)
|
result = newType(k, r.owner)
|
||||||
result.addSonSkipIntLit(r)
|
result.addSonSkipIntLit(r)
|
||||||
|
|
||||||
proc isTopLevel(c: PContext): bool {.inline.} =
|
proc isTopLevel(c: PContext): bool {.inline.} =
|
||||||
|
|
@ -139,27 +158,28 @@ proc IsOpImpl(c: PContext, n: PNode): PNode
|
||||||
proc semMacroExpr(c: PContext, n, nOrig: PNode, sym: PSym,
|
proc semMacroExpr(c: PContext, n, nOrig: PNode, sym: PSym,
|
||||||
semCheck: bool = true): PNode
|
semCheck: bool = true): PNode
|
||||||
|
|
||||||
proc symFromType(t: PType, info: TLineInfo): PSym =
|
when false:
|
||||||
if t.sym != nil: return t.sym
|
proc symFromType(t: PType, info: TLineInfo): PSym =
|
||||||
result = newSym(skType, getIdent"AnonType", t.owner, info)
|
if t.sym != nil: return t.sym
|
||||||
result.flags.incl sfAnon
|
result = newSym(skType, getIdent"AnonType", t.owner, info)
|
||||||
result.typ = t
|
result.flags.incl sfAnon
|
||||||
|
result.typ = t
|
||||||
|
|
||||||
proc symNodeFromType(c: PContext, t: PType, info: TLineInfo): PNode =
|
proc symNodeFromType(c: PContext, t: PType, info: TLineInfo): PNode =
|
||||||
result = newSymNode(symFromType(t, info), info)
|
result = newSymNode(symFromType(t, info), info)
|
||||||
result.typ = makeTypeDesc(c, t)
|
result.typ = makeTypeDesc(c, t)
|
||||||
|
|
||||||
when false:
|
when false:
|
||||||
proc createEvalContext(c: PContext, mode: TEvalMode): PEvalContext =
|
proc createEvalContext(c: PContext, mode: TEvalMode): PEvalContext =
|
||||||
result = newEvalContext(c.module, mode)
|
result = newEvalContext(c.module, mode)
|
||||||
result.getType = proc (n: PNode): PNode =
|
result.getType = proc (n: PNode): PNode =
|
||||||
var e = tryExpr(c, n)
|
result = tryExpr(c, n)
|
||||||
if e == nil:
|
if result == nil:
|
||||||
result = symNodeFromType(c, errorType(c), n.info)
|
result = newSymNode(errorSym(c, n))
|
||||||
elif e.typ == nil:
|
elif result.typ == nil:
|
||||||
result = newSymNode(getSysSym"void")
|
result = newSymNode(getSysSym"void")
|
||||||
else:
|
else:
|
||||||
result = symNodeFromType(c, e.typ, n.info)
|
result.typ = makeTypeDesc(c, result.typ)
|
||||||
|
|
||||||
result.handleIsOperator = proc (n: PNode): PNode =
|
result.handleIsOperator = proc (n: PNode): PNode =
|
||||||
result = IsOpImpl(c, n)
|
result = IsOpImpl(c, n)
|
||||||
|
|
@ -215,7 +235,8 @@ proc semAfterMacroCall(c: PContext, n: PNode, s: PSym): PNode =
|
||||||
of tyTypeDesc:
|
of tyTypeDesc:
|
||||||
if n.kind == nkStmtList: result.kind = nkStmtListType
|
if n.kind == nkStmtList: result.kind = nkStmtListType
|
||||||
var typ = semTypeNode(c, result, nil)
|
var typ = semTypeNode(c, result, nil)
|
||||||
result = symNodeFromType(c, typ, n.info)
|
result.typ = makeTypeDesc(c, typ)
|
||||||
|
#result = symNodeFromType(c, typ, n.info)
|
||||||
else:
|
else:
|
||||||
result = semExpr(c, result)
|
result = semExpr(c, result)
|
||||||
result = fitNode(c, s.typ.sons[0], result)
|
result = fitNode(c, s.typ.sons[0], result)
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,7 @@ type
|
||||||
threadEntries*: TSymSeq # list of thread entries to check
|
threadEntries*: TSymSeq # list of thread entries to check
|
||||||
AmbiguousSymbols*: TIntSet # ids of all ambiguous symbols (cannot
|
AmbiguousSymbols*: TIntSet # ids of all ambiguous symbols (cannot
|
||||||
# store this info in the syms themselves!)
|
# store this info in the syms themselves!)
|
||||||
|
InTypeClass*: int # > 0 if we are in a user-defined type class
|
||||||
InGenericContext*: int # > 0 if we are in a generic type
|
InGenericContext*: int # > 0 if we are in a generic type
|
||||||
InUnrolledContext*: int # > 0 if we are unrolling a loop
|
InUnrolledContext*: int # > 0 if we are unrolling a loop
|
||||||
InCompilesContext*: int # > 0 if we are in a ``compiles`` magic
|
InCompilesContext*: int # > 0 if we are in a ``compiles`` magic
|
||||||
|
|
@ -72,7 +73,8 @@ type
|
||||||
libs*: TLinkedList # all libs used by this module
|
libs*: TLinkedList # all libs used by this module
|
||||||
semConstExpr*: proc (c: PContext, n: PNode): PNode {.nimcall.} # for the pragmas
|
semConstExpr*: proc (c: PContext, n: PNode): PNode {.nimcall.} # for the pragmas
|
||||||
semExpr*: proc (c: PContext, n: PNode, flags: TExprFlags = {}): PNode {.nimcall.}
|
semExpr*: proc (c: PContext, n: PNode, flags: TExprFlags = {}): PNode {.nimcall.}
|
||||||
semTryExpr*: proc (c: PContext, n: PNode, flags: TExprFlags = {}): PNode {.nimcall.}
|
semTryExpr*: proc (c: PContext, n: PNode,flags: TExprFlags = {},
|
||||||
|
bufferErrors = false): PNode {.nimcall.}
|
||||||
semOperand*: proc (c: PContext, n: PNode, flags: TExprFlags = {}): PNode {.nimcall.}
|
semOperand*: proc (c: PContext, n: PNode, flags: TExprFlags = {}): PNode {.nimcall.}
|
||||||
semConstBoolExpr*: proc (c: PContext, n: PNode): PNode {.nimcall.} # XXX bite the bullet
|
semConstBoolExpr*: proc (c: PContext, n: PNode): PNode {.nimcall.} # XXX bite the bullet
|
||||||
semOverloadedCall*: proc (c: PContext, n, nOrig: PNode,
|
semOverloadedCall*: proc (c: PContext, n, nOrig: PNode,
|
||||||
|
|
|
||||||
|
|
@ -191,7 +191,7 @@ proc isCastable(dst, src: PType): bool =
|
||||||
proc isSymChoice(n: PNode): bool {.inline.} =
|
proc isSymChoice(n: PNode): bool {.inline.} =
|
||||||
result = n.kind in nkSymChoices
|
result = n.kind in nkSymChoices
|
||||||
|
|
||||||
proc semConv(c: PContext, n: PNode, s: PSym): PNode =
|
proc semConv(c: PContext, n: PNode): PNode =
|
||||||
if sonsLen(n) != 2:
|
if sonsLen(n) != 2:
|
||||||
LocalError(n.info, errConvNeedsOneArg)
|
LocalError(n.info, errConvNeedsOneArg)
|
||||||
return n
|
return n
|
||||||
|
|
@ -299,7 +299,7 @@ proc semOf(c: PContext, n: PNode): PNode =
|
||||||
n.typ = getSysType(tyBool)
|
n.typ = getSysType(tyBool)
|
||||||
result = n
|
result = n
|
||||||
|
|
||||||
proc IsOpImpl(c: PContext, n: PNode): PNode =
|
proc isOpImpl(c: PContext, n: PNode): PNode =
|
||||||
InternalAssert n.sonsLen == 3 and
|
InternalAssert n.sonsLen == 3 and
|
||||||
n[1].kind == nkSym and n[1].sym.kind == skType and
|
n[1].kind == nkSym and n[1].sym.kind == skType and
|
||||||
n[2].kind in {nkStrLit..nkTripleStrLit, nkType}
|
n[2].kind in {nkStrLit..nkTripleStrLit, nkType}
|
||||||
|
|
@ -321,10 +321,19 @@ proc IsOpImpl(c: PContext, n: PNode): PNode =
|
||||||
else:
|
else:
|
||||||
var match: bool
|
var match: bool
|
||||||
let t2 = n[2].typ
|
let t2 = n[2].typ
|
||||||
if t2.kind == tyTypeClass:
|
case t2.kind
|
||||||
|
of tyTypeClass:
|
||||||
var m: TCandidate
|
var m: TCandidate
|
||||||
InitCandidate(m, t2)
|
InitCandidate(m, t2)
|
||||||
match = matchUserTypeClass(c, m, emptyNode, t2, t1) != nil
|
match = matchUserTypeClass(c, m, emptyNode, t2, t1) != nil
|
||||||
|
of tyOrdinal:
|
||||||
|
var m: TCandidate
|
||||||
|
InitCandidate(m, t2)
|
||||||
|
match = isOrdinalType(t1)
|
||||||
|
of tySequence, tyArray, tySet:
|
||||||
|
var m: TCandidate
|
||||||
|
InitCandidate(m, t2)
|
||||||
|
match = typeRel(m, t2, t1) != isNone
|
||||||
else:
|
else:
|
||||||
match = sameType(t1, t2)
|
match = sameType(t1, t2)
|
||||||
|
|
||||||
|
|
@ -353,7 +362,7 @@ proc semIs(c: PContext, n: PNode): PNode =
|
||||||
|
|
||||||
let t1 = n[1].typ.sons[0]
|
let t1 = n[1].typ.sons[0]
|
||||||
# BUGFIX: don't evaluate this too early: ``T is void``
|
# BUGFIX: don't evaluate this too early: ``T is void``
|
||||||
if not containsGenericType(t1): result = IsOpImpl(c, n)
|
if not containsGenericType(t1): result = isOpImpl(c, n)
|
||||||
|
|
||||||
proc semOpAux(c: PContext, n: PNode) =
|
proc semOpAux(c: PContext, n: PNode) =
|
||||||
const flags = {efDetermineType}
|
const flags = {efDetermineType}
|
||||||
|
|
@ -729,8 +738,7 @@ proc semIndirectOp(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
elif t != nil and t.kind == tyTypeDesc:
|
elif t != nil and t.kind == tyTypeDesc:
|
||||||
if n.len == 1: return semObjConstr(c, n, flags)
|
if n.len == 1: return semObjConstr(c, n, flags)
|
||||||
let destType = t.skipTypes({tyTypeDesc, tyGenericInst})
|
let destType = t.skipTypes({tyTypeDesc, tyGenericInst})
|
||||||
result = semConv(c, n, symFromType(destType, n.info))
|
return semConv(c, n)
|
||||||
return
|
|
||||||
else:
|
else:
|
||||||
result = overloadedCallOpr(c, n)
|
result = overloadedCallOpr(c, n)
|
||||||
# Now that nkSym does not imply an iteration over the proc/iterator space,
|
# Now that nkSym does not imply an iteration over the proc/iterator space,
|
||||||
|
|
@ -763,7 +771,8 @@ proc afterCallActions(c: PContext; n, orig: PNode, flags: TExprFlags): PNode =
|
||||||
analyseIfAddressTakenInCall(c, result)
|
analyseIfAddressTakenInCall(c, result)
|
||||||
if callee.magic != mNone:
|
if callee.magic != mNone:
|
||||||
result = magicsAfterOverloadResolution(c, result, flags)
|
result = magicsAfterOverloadResolution(c, result, flags)
|
||||||
result = evalAtCompileTime(c, result)
|
if c.InTypeClass == 0:
|
||||||
|
result = evalAtCompileTime(c, result)
|
||||||
|
|
||||||
proc semDirectOp(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
proc semDirectOp(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
# this seems to be a hotspot in the compiler!
|
# this seems to be a hotspot in the compiler!
|
||||||
|
|
@ -814,7 +823,7 @@ proc buildEchoStmt(c: PContext, n: PNode): PNode =
|
||||||
|
|
||||||
proc semExprNoType(c: PContext, n: PNode): PNode =
|
proc semExprNoType(c: PContext, n: PNode): PNode =
|
||||||
result = semExpr(c, n, {efWantStmt})
|
result = semExpr(c, n, {efWantStmt})
|
||||||
discardCheck(result)
|
discardCheck(c, result)
|
||||||
|
|
||||||
proc isTypeExpr(n: PNode): bool =
|
proc isTypeExpr(n: PNode): bool =
|
||||||
case n.kind
|
case n.kind
|
||||||
|
|
@ -1038,7 +1047,9 @@ proc semSubscript(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
# The result so far is a tyTypeDesc bound
|
# The result so far is a tyTypeDesc bound
|
||||||
# a tyGenericBody. The line below will substitute
|
# a tyGenericBody. The line below will substitute
|
||||||
# it with the instantiated type.
|
# it with the instantiated type.
|
||||||
result = symNodeFromType(c, semTypeNode(c, n, nil), n.info)
|
result = n
|
||||||
|
result.typ = makeTypeDesc(c, semTypeNode(c, n, nil))
|
||||||
|
#result = symNodeFromType(c, semTypeNode(c, n, nil), n.info)
|
||||||
of tyTuple:
|
of tyTuple:
|
||||||
checkSonsLen(n, 2)
|
checkSonsLen(n, 2)
|
||||||
n.sons[0] = makeDeref(n.sons[0])
|
n.sons[0] = makeDeref(n.sons[0])
|
||||||
|
|
@ -1208,7 +1219,7 @@ proc semProcBody(c: PContext, n: PNode): PNode =
|
||||||
a.sons[1] = result
|
a.sons[1] = result
|
||||||
result = semAsgn(c, a)
|
result = semAsgn(c, a)
|
||||||
else:
|
else:
|
||||||
discardCheck(result)
|
discardCheck(c, result)
|
||||||
closeScope(c)
|
closeScope(c)
|
||||||
|
|
||||||
proc SemYieldVarResult(c: PContext, n: PNode, restype: PType) =
|
proc SemYieldVarResult(c: PContext, n: PNode, restype: PType) =
|
||||||
|
|
@ -1429,12 +1440,12 @@ proc semQuoteAst(c: PContext, n: PNode): PNode =
|
||||||
newNode(nkCall, n.info, quotes)])
|
newNode(nkCall, n.info, quotes)])
|
||||||
result = semExpandToAst(c, result)
|
result = semExpandToAst(c, result)
|
||||||
|
|
||||||
proc tryExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
|
proc tryExpr(c: PContext, n: PNode,
|
||||||
|
flags: TExprFlags = {}, bufferErrors = false): PNode =
|
||||||
# watch out, hacks ahead:
|
# watch out, hacks ahead:
|
||||||
let oldErrorCount = msgs.gErrorCounter
|
let oldErrorCount = msgs.gErrorCounter
|
||||||
let oldErrorMax = msgs.gErrorMax
|
let oldErrorMax = msgs.gErrorMax
|
||||||
inc c.InCompilesContext
|
inc c.InCompilesContext
|
||||||
inc msgs.gSilence
|
|
||||||
# do not halt after first error:
|
# do not halt after first error:
|
||||||
msgs.gErrorMax = high(int)
|
msgs.gErrorMax = high(int)
|
||||||
|
|
||||||
|
|
@ -1443,6 +1454,8 @@ proc tryExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
|
||||||
openScope(c)
|
openScope(c)
|
||||||
let oldOwnerLen = len(gOwners)
|
let oldOwnerLen = len(gOwners)
|
||||||
let oldGenerics = c.generics
|
let oldGenerics = c.generics
|
||||||
|
let oldErrorOutputs = errorOutputs
|
||||||
|
errorOutputs = if bufferErrors: {eInMemory} else: {}
|
||||||
let oldContextLen = msgs.getInfoContextLen()
|
let oldContextLen = msgs.getInfoContextLen()
|
||||||
|
|
||||||
let oldInGenericContext = c.InGenericContext
|
let oldInGenericContext = c.InGenericContext
|
||||||
|
|
@ -1465,7 +1478,7 @@ proc tryExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
|
||||||
setlen(gOwners, oldOwnerLen)
|
setlen(gOwners, oldOwnerLen)
|
||||||
c.currentScope = oldScope
|
c.currentScope = oldScope
|
||||||
dec c.InCompilesContext
|
dec c.InCompilesContext
|
||||||
dec msgs.gSilence
|
errorOutputs = oldErrorOutputs
|
||||||
msgs.gErrorCounter = oldErrorCount
|
msgs.gErrorCounter = oldErrorCount
|
||||||
msgs.gErrorMax = oldErrorMax
|
msgs.gErrorMax = oldErrorMax
|
||||||
|
|
||||||
|
|
@ -1871,7 +1884,8 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
|
||||||
result = semExpr(c, n.sons[0], flags)
|
result = semExpr(c, n.sons[0], flags)
|
||||||
of nkTypeOfExpr, nkTupleTy, nkRefTy..nkEnumTy:
|
of nkTypeOfExpr, nkTupleTy, nkRefTy..nkEnumTy:
|
||||||
var typ = semTypeNode(c, n, nil).skipTypes({tyTypeDesc})
|
var typ = semTypeNode(c, n, nil).skipTypes({tyTypeDesc})
|
||||||
result = symNodeFromType(c, typ, n.info)
|
result.typ = makeTypeDesc(c, typ)
|
||||||
|
#result = symNodeFromType(c, typ, n.info)
|
||||||
of nkCall, nkInfix, nkPrefix, nkPostfix, nkCommand, nkCallStrLit:
|
of nkCall, nkInfix, nkPrefix, nkPostfix, nkCommand, nkCallStrLit:
|
||||||
# check if it is an expression macro:
|
# check if it is an expression macro:
|
||||||
checkMinSonsLen(n, 1)
|
checkMinSonsLen(n, 1)
|
||||||
|
|
@ -1894,7 +1908,7 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
|
||||||
of skType:
|
of skType:
|
||||||
# XXX think about this more (``set`` procs)
|
# XXX think about this more (``set`` procs)
|
||||||
if n.len == 2:
|
if n.len == 2:
|
||||||
result = semConv(c, n, s)
|
result = semConv(c, n)
|
||||||
elif n.len == 1:
|
elif n.len == 1:
|
||||||
result = semObjConstr(c, n, flags)
|
result = semObjConstr(c, n, flags)
|
||||||
elif Contains(c.AmbiguousSymbols, s.id):
|
elif Contains(c.AmbiguousSymbols, s.id):
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@ proc fixNilType(n: PNode) =
|
||||||
for it in n: fixNilType(it)
|
for it in n: fixNilType(it)
|
||||||
n.typ = nil
|
n.typ = nil
|
||||||
|
|
||||||
proc discardCheck(result: PNode) =
|
proc discardCheck(c: PContext, result: PNode) =
|
||||||
if result.typ != nil and result.typ.kind notin {tyStmt, tyEmpty}:
|
if result.typ != nil and result.typ.kind notin {tyStmt, tyEmpty}:
|
||||||
if result.kind == nkNilLit:
|
if result.kind == nkNilLit:
|
||||||
result.typ = nil
|
result.typ = nil
|
||||||
|
|
@ -142,6 +142,10 @@ proc discardCheck(result: PNode) =
|
||||||
while n.kind in skipForDiscardable:
|
while n.kind in skipForDiscardable:
|
||||||
n = n.lastSon
|
n = n.lastSon
|
||||||
n.typ = nil
|
n.typ = nil
|
||||||
|
elif c.InTypeClass > 0 and result.typ.kind == tyBool:
|
||||||
|
let verdict = semConstExpr(c, result)
|
||||||
|
if verdict.intVal == 0:
|
||||||
|
localError(result.info, "type class predicate failed.")
|
||||||
elif result.typ.kind != tyError and gCmd != cmdInteractive:
|
elif result.typ.kind != tyError and gCmd != cmdInteractive:
|
||||||
if result.typ.kind == tyNil:
|
if result.typ.kind == tyNil:
|
||||||
fixNilType(result)
|
fixNilType(result)
|
||||||
|
|
@ -169,7 +173,7 @@ proc semIf(c: PContext, n: PNode): PNode =
|
||||||
typ = commonType(typ, it.sons[0].typ)
|
typ = commonType(typ, it.sons[0].typ)
|
||||||
else: illFormedAst(it)
|
else: illFormedAst(it)
|
||||||
if isEmptyType(typ) or typ.kind == tyNil or not hasElse:
|
if isEmptyType(typ) or typ.kind == tyNil or not hasElse:
|
||||||
for it in n: discardCheck(it.lastSon)
|
for it in n: discardCheck(c, it.lastSon)
|
||||||
result.kind = nkIfStmt
|
result.kind = nkIfStmt
|
||||||
# propagate any enforced VoidContext:
|
# propagate any enforced VoidContext:
|
||||||
if typ == EnforceVoidContext: result.typ = EnforceVoidContext
|
if typ == EnforceVoidContext: result.typ = EnforceVoidContext
|
||||||
|
|
@ -230,7 +234,7 @@ proc semCase(c: PContext, n: PNode): PNode =
|
||||||
localError(n.info, errNotAllCasesCovered)
|
localError(n.info, errNotAllCasesCovered)
|
||||||
closeScope(c)
|
closeScope(c)
|
||||||
if isEmptyType(typ) or typ.kind == tyNil or not hasElse:
|
if isEmptyType(typ) or typ.kind == tyNil or not hasElse:
|
||||||
for i in 1..n.len-1: discardCheck(n.sons[i].lastSon)
|
for i in 1..n.len-1: discardCheck(c, n.sons[i].lastSon)
|
||||||
# propagate any enforced VoidContext:
|
# propagate any enforced VoidContext:
|
||||||
if typ == EnforceVoidContext:
|
if typ == EnforceVoidContext:
|
||||||
result.typ = EnforceVoidContext
|
result.typ = EnforceVoidContext
|
||||||
|
|
@ -275,8 +279,8 @@ proc semTry(c: PContext, n: PNode): PNode =
|
||||||
typ = commonType(typ, a.sons[length-1].typ)
|
typ = commonType(typ, a.sons[length-1].typ)
|
||||||
dec c.p.inTryStmt
|
dec c.p.inTryStmt
|
||||||
if isEmptyType(typ) or typ.kind == tyNil:
|
if isEmptyType(typ) or typ.kind == tyNil:
|
||||||
discardCheck(n.sons[0])
|
discardCheck(c, n.sons[0])
|
||||||
for i in 1..n.len-1: discardCheck(n.sons[i].lastSon)
|
for i in 1..n.len-1: discardCheck(c, n.sons[i].lastSon)
|
||||||
if typ == EnforceVoidContext:
|
if typ == EnforceVoidContext:
|
||||||
result.typ = EnforceVoidContext
|
result.typ = EnforceVoidContext
|
||||||
else:
|
else:
|
||||||
|
|
@ -882,7 +886,8 @@ proc semLambda(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
if n.sons[genericParamsPos].kind != nkEmpty:
|
if n.sons[genericParamsPos].kind != nkEmpty:
|
||||||
illFormedAst(n) # process parameters:
|
illFormedAst(n) # process parameters:
|
||||||
if n.sons[paramsPos].kind != nkEmpty:
|
if n.sons[paramsPos].kind != nkEmpty:
|
||||||
semParamList(c, n.sons[ParamsPos], nil, s)
|
var gp = newNodeI(nkGenericParams, n.info)
|
||||||
|
semParamList(c, n.sons[ParamsPos], gp, s)
|
||||||
ParamsTypeCheck(c, s.typ)
|
ParamsTypeCheck(c, s.typ)
|
||||||
else:
|
else:
|
||||||
s.typ = newTypeS(tyProc, c)
|
s.typ = newTypeS(tyProc, c)
|
||||||
|
|
@ -1084,6 +1089,8 @@ proc semIterator(c: PContext, n: PNode): PNode =
|
||||||
# -- at least for 0.9.2.
|
# -- at least for 0.9.2.
|
||||||
if s.typ.callConv == ccClosure:
|
if s.typ.callConv == ccClosure:
|
||||||
incl(s.typ.flags, tfCapturesEnv)
|
incl(s.typ.flags, tfCapturesEnv)
|
||||||
|
else:
|
||||||
|
s.typ.callConv = ccInline
|
||||||
when false:
|
when false:
|
||||||
if s.typ.callConv != ccInline:
|
if s.typ.callConv != ccInline:
|
||||||
s.typ.callConv = ccClosure
|
s.typ.callConv = ccClosure
|
||||||
|
|
@ -1106,24 +1113,24 @@ proc finishMethod(c: PContext, s: PSym) =
|
||||||
methodDef(s, false)
|
methodDef(s, false)
|
||||||
|
|
||||||
proc semMethod(c: PContext, n: PNode): PNode =
|
proc semMethod(c: PContext, n: PNode): PNode =
|
||||||
if not isTopLevel(c): LocalError(n.info, errXOnlyAtModuleScope, "method")
|
if not isTopLevel(c): localError(n.info, errXOnlyAtModuleScope, "method")
|
||||||
result = semProcAux(c, n, skMethod, methodPragmas)
|
result = semProcAux(c, n, skMethod, methodPragmas)
|
||||||
|
|
||||||
var s = result.sons[namePos].sym
|
var s = result.sons[namePos].sym
|
||||||
if not isGenericRoutine(s):
|
if not isGenericRoutine(s) and result.sons[bodyPos].kind != nkEmpty:
|
||||||
if hasObjParam(s):
|
if hasObjParam(s):
|
||||||
methodDef(s, false)
|
methodDef(s, fromCache=false)
|
||||||
else:
|
else:
|
||||||
LocalError(n.info, errXNeedsParamObjectType, "method")
|
localError(n.info, errXNeedsParamObjectType, "method")
|
||||||
|
|
||||||
proc semConverterDef(c: PContext, n: PNode): PNode =
|
proc semConverterDef(c: PContext, n: PNode): PNode =
|
||||||
if not isTopLevel(c): LocalError(n.info, errXOnlyAtModuleScope, "converter")
|
if not isTopLevel(c): localError(n.info, errXOnlyAtModuleScope, "converter")
|
||||||
checkSonsLen(n, bodyPos + 1)
|
checkSonsLen(n, bodyPos + 1)
|
||||||
result = semProcAux(c, n, skConverter, converterPragmas)
|
result = semProcAux(c, n, skConverter, converterPragmas)
|
||||||
var s = result.sons[namePos].sym
|
var s = result.sons[namePos].sym
|
||||||
var t = s.typ
|
var t = s.typ
|
||||||
if t.sons[0] == nil: LocalError(n.info, errXNeedsReturnType, "converter")
|
if t.sons[0] == nil: localError(n.info, errXNeedsReturnType, "converter")
|
||||||
if sonsLen(t) != 2: LocalError(n.info, errXRequiresOneArgument, "converter")
|
if sonsLen(t) != 2: localError(n.info, errXRequiresOneArgument, "converter")
|
||||||
addConverter(c, s)
|
addConverter(c, s)
|
||||||
|
|
||||||
proc semMacroDef(c: PContext, n: PNode): PNode =
|
proc semMacroDef(c: PContext, n: PNode): PNode =
|
||||||
|
|
@ -1131,9 +1138,9 @@ proc semMacroDef(c: PContext, n: PNode): PNode =
|
||||||
result = semProcAux(c, n, skMacro, macroPragmas)
|
result = semProcAux(c, n, skMacro, macroPragmas)
|
||||||
var s = result.sons[namePos].sym
|
var s = result.sons[namePos].sym
|
||||||
var t = s.typ
|
var t = s.typ
|
||||||
if t.sons[0] == nil: LocalError(n.info, errXNeedsReturnType, "macro")
|
if t.sons[0] == nil: localError(n.info, errXNeedsReturnType, "macro")
|
||||||
if n.sons[bodyPos].kind == nkEmpty:
|
if n.sons[bodyPos].kind == nkEmpty:
|
||||||
LocalError(n.info, errImplOfXexpected, s.name.s)
|
localError(n.info, errImplOfXexpected, s.name.s)
|
||||||
|
|
||||||
proc evalInclude(c: PContext, n: PNode): PNode =
|
proc evalInclude(c: PContext, n: PNode): PNode =
|
||||||
result = newNodeI(nkStmtList, n.info)
|
result = newNodeI(nkStmtList, n.info)
|
||||||
|
|
@ -1223,7 +1230,7 @@ proc semStmtList(c: PContext, n: PNode): PNode =
|
||||||
voidContext = true
|
voidContext = true
|
||||||
n.typ = EnforceVoidContext
|
n.typ = EnforceVoidContext
|
||||||
if i != last or voidContext:
|
if i != last or voidContext:
|
||||||
discardCheck(n.sons[i])
|
discardCheck(c, n.sons[i])
|
||||||
else:
|
else:
|
||||||
n.typ = n.sons[i].typ
|
n.typ = n.sons[i].typ
|
||||||
if not isEmptyType(n.typ):
|
if not isEmptyType(n.typ):
|
||||||
|
|
|
||||||
|
|
@ -876,8 +876,7 @@ proc freshType(res, prev: PType): PType {.inline.} =
|
||||||
proc semTypeClass(c: PContext, n: PNode, prev: PType): PType =
|
proc semTypeClass(c: PContext, n: PNode, prev: PType): PType =
|
||||||
# if n.sonsLen == 0: return newConstraint(c, tyTypeClass)
|
# if n.sonsLen == 0: return newConstraint(c, tyTypeClass)
|
||||||
result = newOrPrevType(tyTypeClass, prev, c)
|
result = newOrPrevType(tyTypeClass, prev, c)
|
||||||
result.testeeName = considerAcc(n[0])
|
result.n = n
|
||||||
result.n = n[3]
|
|
||||||
|
|
||||||
let
|
let
|
||||||
pragmas = n[1]
|
pragmas = n[1]
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,7 @@ proc initCandidate*(c: var TCandidate, callee: PSym, binding: PNode,
|
||||||
c.calleeSym = callee
|
c.calleeSym = callee
|
||||||
c.calleeScope = calleeScope
|
c.calleeScope = calleeScope
|
||||||
initIdTable(c.bindings)
|
initIdTable(c.bindings)
|
||||||
|
c.errors = nil
|
||||||
if binding != nil and callee.kind in RoutineKinds:
|
if binding != nil and callee.kind in RoutineKinds:
|
||||||
var typeParams = callee.ast[genericParamsPos]
|
var typeParams = callee.ast[genericParamsPos]
|
||||||
for i in 1..min(sonsLen(typeParams), sonsLen(binding)-1):
|
for i in 1..min(sonsLen(typeParams), sonsLen(binding)-1):
|
||||||
|
|
@ -202,7 +203,7 @@ proc describeArgs*(c: PContext, n: PNode, startIdx = 1): string =
|
||||||
add(result, argTypeToString(arg))
|
add(result, argTypeToString(arg))
|
||||||
if i != sonsLen(n) - 1: add(result, ", ")
|
if i != sonsLen(n) - 1: add(result, ", ")
|
||||||
|
|
||||||
proc typeRel(c: var TCandidate, f, a: PType): TTypeRelation
|
proc typeRel*(c: var TCandidate, f, a: PType): TTypeRelation
|
||||||
proc concreteType(c: TCandidate, t: PType): PType =
|
proc concreteType(c: TCandidate, t: PType): PType =
|
||||||
case t.kind
|
case t.kind
|
||||||
of tyArrayConstr:
|
of tyArrayConstr:
|
||||||
|
|
@ -750,40 +751,55 @@ proc matchUserTypeClass*(c: PContext, m: var TCandidate,
|
||||||
|
|
||||||
# pushInfoContext(arg.info)
|
# pushInfoContext(arg.info)
|
||||||
openScope(c)
|
openScope(c)
|
||||||
|
inc c.InTypeClass
|
||||||
|
|
||||||
var testee = newSym(skParam, f.testeeName, f.sym, f.sym.info)
|
finally:
|
||||||
testee.typ = a
|
dec c.InTypeClass
|
||||||
addDecl(c, testee)
|
closeScope(c)
|
||||||
|
|
||||||
|
for param in f.n[0]:
|
||||||
|
var
|
||||||
|
dummyName: PNode
|
||||||
|
dummyType: PType
|
||||||
|
|
||||||
|
if param.kind == nkVarTy:
|
||||||
|
dummyName = param[0]
|
||||||
|
dummyType = makeVarType(c, a)
|
||||||
|
else:
|
||||||
|
dummyName = param
|
||||||
|
dummyType = a
|
||||||
|
|
||||||
|
InternalAssert dummyName.kind == nkIdent
|
||||||
|
var dummyParam = newSym(skType, dummyName.ident, f.sym, f.sym.info)
|
||||||
|
dummyParam.typ = dummyType
|
||||||
|
addDecl(c, dummyParam)
|
||||||
|
|
||||||
|
for stmt in f.n[3]:
|
||||||
|
var e = c.semTryExpr(c, copyTree(stmt), bufferErrors = false)
|
||||||
|
m.errors = bufferedMsgs
|
||||||
|
clearBufferedMsgs()
|
||||||
|
if e == nil: return nil
|
||||||
|
|
||||||
for stmt in f.n:
|
|
||||||
var e = c.semTryExpr(c, copyTree(stmt))
|
|
||||||
if e == nil:
|
|
||||||
let expStr = renderTree(stmt, {renderNoComments})
|
|
||||||
m.errors.safeAdd("can't compile " & expStr & " for " & a.typeToString)
|
|
||||||
return nil
|
|
||||||
case e.kind
|
case e.kind
|
||||||
of nkReturnStmt:
|
of nkReturnStmt: nil
|
||||||
nil
|
|
||||||
of nkTypeSection: nil
|
of nkTypeSection: nil
|
||||||
of nkConstDef: nil
|
of nkConstDef: nil
|
||||||
else:
|
else: nil
|
||||||
if e.typ.kind == tyBool:
|
|
||||||
let verdict = c.semConstExpr(c, e)
|
|
||||||
if verdict.intVal == 0:
|
|
||||||
let expStr = renderTree(stmt, {renderNoComments})
|
|
||||||
m.errors.safeAdd(expStr & " doesn't hold for " & a.typeToString)
|
|
||||||
return nil
|
|
||||||
|
|
||||||
closeScope(c)
|
|
||||||
|
|
||||||
result = arg
|
result = arg
|
||||||
put(m.bindings, f, a)
|
put(m.bindings, f, a)
|
||||||
|
|
||||||
proc ParamTypesMatchAux(c: PContext, m: var TCandidate, f, a: PType,
|
proc ParamTypesMatchAux(c: PContext, m: var TCandidate, f, argType: PType,
|
||||||
argSemantized, argOrig: PNode): PNode =
|
argSemantized, argOrig: PNode): PNode =
|
||||||
var arg = argSemantized
|
var
|
||||||
var r: TTypeRelation
|
r: TTypeRelation
|
||||||
let fMaybeExpr = f.skipTypes({tyDistinct})
|
arg = argSemantized
|
||||||
|
|
||||||
|
let
|
||||||
|
a = if c.InTypeClass > 0: argType.skipTypes({tyTypeDesc})
|
||||||
|
else: argType
|
||||||
|
fMaybeExpr = f.skipTypes({tyDistinct})
|
||||||
|
|
||||||
case fMaybeExpr.kind
|
case fMaybeExpr.kind
|
||||||
of tyExpr:
|
of tyExpr:
|
||||||
if fMaybeExpr.sonsLen == 0:
|
if fMaybeExpr.sonsLen == 0:
|
||||||
|
|
|
||||||
|
|
@ -837,8 +837,12 @@ proc SameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
|
||||||
result = sameObjectStructures(a, b, c) and sameFlags(a, b)
|
result = sameObjectStructures(a, b, c) and sameFlags(a, b)
|
||||||
of tyDistinct:
|
of tyDistinct:
|
||||||
CycleCheck()
|
CycleCheck()
|
||||||
if c.cmp == dcEq: result = sameDistinctTypes(a, b) and sameFlags(a, b)
|
if c.cmp == dcEq:
|
||||||
else: result = sameTypeAux(a.sons[0], b.sons[0], c) and sameFlags(a, b)
|
if sameFlags(a, b):
|
||||||
|
IfFastObjectTypeCheckFailed(a, b):
|
||||||
|
result = sameTypeAux(a.sons[0], b.sons[0], c)
|
||||||
|
else:
|
||||||
|
result = sameTypeAux(a.sons[0], b.sons[0], c) and sameFlags(a, b)
|
||||||
of tyEnum, tyForward, tyProxy:
|
of tyEnum, tyForward, tyProxy:
|
||||||
# XXX generic enums do not make much sense, but require structural checking
|
# XXX generic enums do not make much sense, but require structural checking
|
||||||
result = a.id == b.id and sameFlags(a, b)
|
result = a.id == b.id and sameFlags(a, b)
|
||||||
|
|
|
||||||
|
|
@ -18,14 +18,14 @@ path="$lib/pure"
|
||||||
path="$lib/pure/collections"
|
path="$lib/pure/collections"
|
||||||
path="$lib/impure"
|
path="$lib/impure"
|
||||||
path="$lib/wrappers"
|
path="$lib/wrappers"
|
||||||
path="$lib/wrappers/cairo"
|
# path="$lib/wrappers/cairo"
|
||||||
path="$lib/wrappers/gtk"
|
# path="$lib/wrappers/gtk"
|
||||||
path="$lib/wrappers/lua"
|
# path="$lib/wrappers/lua"
|
||||||
path="$lib/wrappers/opengl"
|
# path="$lib/wrappers/opengl"
|
||||||
path="$lib/wrappers/pcre"
|
path="$lib/wrappers/pcre"
|
||||||
path="$lib/wrappers/readline"
|
path="$lib/wrappers/readline"
|
||||||
path="$lib/wrappers/sdl"
|
path="$lib/wrappers/sdl"
|
||||||
path="$lib/wrappers/x11"
|
# path="$lib/wrappers/x11"
|
||||||
path="$lib/wrappers/zip"
|
path="$lib/wrappers/zip"
|
||||||
path="$lib/wrappers/libffi"
|
path="$lib/wrappers/libffi"
|
||||||
path="$lib/windows"
|
path="$lib/windows"
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ Introduction
|
||||||
This document describes how the GC works and how to tune it for
|
This document describes how the GC works and how to tune it for
|
||||||
(soft) `realtime systems`:idx:.
|
(soft) `realtime systems`:idx:.
|
||||||
|
|
||||||
The basic algorithm is *Deferrent Reference Counting* with cycle detection.
|
The basic algorithm is *Deferred Reference Counting* with cycle detection.
|
||||||
References on the stack are not counted for better performance (and easier C
|
References on the stack are not counted for better performance (and easier C
|
||||||
code generation). The GC **never** scans the whole heap but it may scan the
|
code generation). The GC **never** scans the whole heap but it may scan the
|
||||||
delta-subgraph of the heap that changed since its last run.
|
delta-subgraph of the heap that changed since its last run.
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,11 @@ For a release version use::
|
||||||
nimrod c koch.nim
|
nimrod c koch.nim
|
||||||
./koch boot -d:release
|
./koch boot -d:release
|
||||||
|
|
||||||
|
And for a debug version compatible with GDB::
|
||||||
|
|
||||||
|
nimrod c koch.nim
|
||||||
|
./koch boot --debuginfo --linedir:on
|
||||||
|
|
||||||
The ``koch`` program is Nimrod's maintenance script. It is a replacement for
|
The ``koch`` program is Nimrod's maintenance script. It is a replacement for
|
||||||
make and shell scripting with the advantage that it is much more portable.
|
make and shell scripting with the advantage that it is much more portable.
|
||||||
|
|
||||||
|
|
@ -64,7 +69,7 @@ Coding Guidelines
|
||||||
* Max line length is 80 characters.
|
* Max line length is 80 characters.
|
||||||
* Provide spaces around binary operators if that enhances readability.
|
* Provide spaces around binary operators if that enhances readability.
|
||||||
* Use a space after a colon, but not before it.
|
* Use a space after a colon, but not before it.
|
||||||
* Start types with a capital ``T``, unless they are pointers which start
|
* Start types with a capital ``T``, unless they are pointers/references which start
|
||||||
with ``P``.
|
with ``P``.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,8 @@ Core
|
||||||
Collections and algorithms
|
Collections and algorithms
|
||||||
--------------------------
|
--------------------------
|
||||||
|
|
||||||
|
* `algorithm <algorithm.html>`_
|
||||||
|
Implements some common generic algorithms like sort or binary search.
|
||||||
* `tables <tables.html>`_
|
* `tables <tables.html>`_
|
||||||
Nimrod hash table support. Contains tables, ordered tables and count tables.
|
Nimrod hash table support. Contains tables, ordered tables and count tables.
|
||||||
* `sets <sets.html>`_
|
* `sets <sets.html>`_
|
||||||
|
|
|
||||||
|
|
@ -893,11 +893,12 @@ integers from 0 to ``len(A)-1``. An array expression may be constructed by the
|
||||||
array constructor ``[]``.
|
array constructor ``[]``.
|
||||||
|
|
||||||
`Sequences`:idx: are similar to arrays but of dynamic length which may change
|
`Sequences`:idx: are similar to arrays but of dynamic length which may change
|
||||||
during runtime (like strings). A sequence ``S`` is always indexed by integers
|
during runtime (like strings). Sequences are implemented as growable arrays,
|
||||||
from 0 to ``len(S)-1`` and its bounds are checked. Sequences can be
|
allocating pieces of memory as items are added. A sequence ``S`` is always
|
||||||
constructed by the array constructor ``[]`` in conjunction with the array to
|
indexed by integers from 0 to ``len(S)-1`` and its bounds are checked.
|
||||||
sequence operator ``@``. Another way to allocate space for a sequence is to
|
Sequences can be constructed by the array constructor ``[]`` in conjunction
|
||||||
call the built-in ``newSeq`` procedure.
|
with the array to sequence operator ``@``. Another way to allocate space for a
|
||||||
|
sequence is to call the built-in ``newSeq`` procedure.
|
||||||
|
|
||||||
A sequence may be passed to a parameter that is of type *open array*.
|
A sequence may be passed to a parameter that is of type *open array*.
|
||||||
|
|
||||||
|
|
@ -3288,27 +3289,36 @@ Declarative type classes are written in the following form:
|
||||||
for value in c:
|
for value in c:
|
||||||
type(value) is T
|
type(value) is T
|
||||||
|
|
||||||
|
The type class will be matched if:
|
||||||
The identifiers following the `generic` keyword are treated as variables of
|
|
||||||
the matched type and the body of the type class consists of arbitrary code that
|
|
||||||
must be valid under these circumstances.
|
|
||||||
|
|
||||||
Specifically, the type class will be matched if:
|
|
||||||
|
|
||||||
a) all of the expressions within the body can be compiled for the tested type
|
a) all of the expressions within the body can be compiled for the tested type
|
||||||
b) all statically evaluatable boolean expressions in the body must be true
|
b) all statically evaluatable boolean expressions in the body must be true
|
||||||
|
|
||||||
Please note that the ``is`` operator allows you to easily verify the precise type
|
The identifiers following the `generic` keyword represent instances of the
|
||||||
signatures of the required operations, but since type inference and default
|
currently matched type. These instances can act both as variables of the type,
|
||||||
parameters are still applied in the provided block, it's also possible to encode
|
when used in contexts, where a value is expected, and as the type itself, when
|
||||||
usage protocols that doesn't reveal implementation details.
|
used in a contexts, where a type is expected.
|
||||||
|
|
||||||
|
Please note that the ``is`` operator allows you to easily verify the precise
|
||||||
|
type signatures of the required operations, but since type inference and
|
||||||
|
default parameters are still applied in the provided block, it's also possible
|
||||||
|
to encode usage protocols that doesn't reveal implementation details.
|
||||||
|
|
||||||
|
As a special rule providing further convenience when writing type classes, any
|
||||||
|
type value appearing in a callable expression will be treated as a variable of
|
||||||
|
the designated type for overload resolution purposes, unless the type value was
|
||||||
|
passed in its explicit ``typedesc[T]`` form:
|
||||||
|
|
||||||
|
.. code-block:: nimrod
|
||||||
|
type
|
||||||
|
OutputStream = generic S
|
||||||
|
write(var S, string)
|
||||||
|
|
||||||
Much like generics, the user defined type classes will be instantiated exactly
|
Much like generics, the user defined type classes will be instantiated exactly
|
||||||
once for each tested type and any static code included within them will also be
|
once for each tested type and any static code included within them will also be
|
||||||
executed once.
|
executed once.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Return Type Inference
|
Return Type Inference
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
|
|
@ -4673,9 +4683,10 @@ A proc can be marked with the `noStackFrame`:idx: pragma to tell the compiler
|
||||||
it should not generate a stack frame for the proc. There are also no exit
|
it should not generate a stack frame for the proc. There are also no exit
|
||||||
statements like ``return result;`` generated and the generated C function is
|
statements like ``return result;`` generated and the generated C function is
|
||||||
declared as ``__declspec(naked)`` or ``__attribute__((naked))`` (depending on
|
declared as ``__declspec(naked)`` or ``__attribute__((naked))`` (depending on
|
||||||
the used C compiler). This is useful for procs that only consist of an
|
the used C compiler).
|
||||||
assembler statement.
|
|
||||||
|
|
||||||
|
**Note**: This pragma should only be used by procs which consist solely of assembler
|
||||||
|
statements.
|
||||||
|
|
||||||
error pragma
|
error pragma
|
||||||
------------
|
------------
|
||||||
|
|
|
||||||
62
doc/tut1.txt
62
doc/tut1.txt
|
|
@ -189,9 +189,18 @@ to a storage location:
|
||||||
var x = "abc" # introduces a new variable `x` and assigns a value to it
|
var x = "abc" # introduces a new variable `x` and assigns a value to it
|
||||||
x = "xyz" # assigns a new value to `x`
|
x = "xyz" # assigns a new value to `x`
|
||||||
|
|
||||||
``=`` is the *assignment operator*. The assignment operator cannot
|
``=`` is the *assignment operator*. The assignment operator cannot be
|
||||||
be overloaded, overwritten or forbidden, but this might change in a future
|
overloaded, overwritten or forbidden, but this might change in a future version
|
||||||
version of Nimrod.
|
of Nimrod. You can declare multiple variables with a single assignment
|
||||||
|
statement and all the variables will have the same value:
|
||||||
|
|
||||||
|
.. code-block::
|
||||||
|
var x, y = 3 # assigns 3 to the variables `x` and `y`
|
||||||
|
echo "x ", x # outputs "x 3"
|
||||||
|
echo "y ", y # outputs "y 3"
|
||||||
|
x = 42 # changes `x` to 42 without changing `y`
|
||||||
|
echo "x ", x # outputs "x 42"
|
||||||
|
echo "y ", y # outputs "y 3"
|
||||||
|
|
||||||
|
|
||||||
Constants
|
Constants
|
||||||
|
|
@ -610,7 +619,7 @@ allow to silently throw away a return value:
|
||||||
discard yes("May I ask a pointless question?")
|
discard yes("May I ask a pointless question?")
|
||||||
|
|
||||||
|
|
||||||
The return value can be ignored implicitely if the called proc/iterator has
|
The return value can be ignored implicitly if the called proc/iterator has
|
||||||
been declared with the ``discardable`` pragma:
|
been declared with the ``discardable`` pragma:
|
||||||
|
|
||||||
.. code-block:: nimrod
|
.. code-block:: nimrod
|
||||||
|
|
@ -1077,7 +1086,7 @@ can also be used to include elements (and ranges of elements):
|
||||||
TCharSet = set[char]
|
TCharSet = set[char]
|
||||||
var
|
var
|
||||||
x: TCharSet
|
x: TCharSet
|
||||||
x = {'a'..'z', '0'..'9'} # This constructs a set that conains the
|
x = {'a'..'z', '0'..'9'} # This constructs a set that contains the
|
||||||
# letters from 'a' to 'z' and the digits
|
# letters from 'a' to 'z' and the digits
|
||||||
# from '0' to '9'
|
# from '0' to '9'
|
||||||
|
|
||||||
|
|
@ -1201,7 +1210,7 @@ to specify a range from zero to the specified index minus one:
|
||||||
Sequences
|
Sequences
|
||||||
---------
|
---------
|
||||||
`Sequences`:idx: are similar to arrays but of dynamic length which may change
|
`Sequences`:idx: are similar to arrays but of dynamic length which may change
|
||||||
during runtime (like strings). Since sequences are resizeable they are always
|
during runtime (like strings). Since sequences are resizable they are always
|
||||||
allocated on the heap and garbage collected.
|
allocated on the heap and garbage collected.
|
||||||
|
|
||||||
Sequences are always indexed with an ``int`` starting at position 0.
|
Sequences are always indexed with an ``int`` starting at position 0.
|
||||||
|
|
@ -1352,6 +1361,45 @@ Even though you don't need to declare a type for a tuple to use it, tuples
|
||||||
created with different field names will be considered different objects despite
|
created with different field names will be considered different objects despite
|
||||||
having the same field types.
|
having the same field types.
|
||||||
|
|
||||||
|
Tuples can be *unpacked* during variable assignment (and only then!). This can
|
||||||
|
be handy to assign directly the fields of the tuples to individually named
|
||||||
|
variables. An example of this is the ``splitFile`` proc from the `os module
|
||||||
|
<os.html>`_ which returns the directory, name and extension of a path at the
|
||||||
|
same time. For tuple unpacking to work you have to use parenthesis around the
|
||||||
|
values you want to assign the unpacking to, otherwise you will be assigning the
|
||||||
|
same value to all the individual variables! Example:
|
||||||
|
|
||||||
|
.. code-block:: nimrod
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
let
|
||||||
|
path = "usr/local/nimrodc.html"
|
||||||
|
(dir, name, ext) = splitFile(path)
|
||||||
|
baddir, badname, badext = splitFile(path)
|
||||||
|
echo dir # outputs `usr/local`
|
||||||
|
echo name # outputs `nimrodc`
|
||||||
|
echo ext # outputs `.html`
|
||||||
|
# All the following output the same line:
|
||||||
|
# `(dir: usr/local, name: nimrodc, ext: .html)`
|
||||||
|
echo baddir
|
||||||
|
echo badname
|
||||||
|
echo badext
|
||||||
|
|
||||||
|
Tuple unpacking **only** works in ``var`` or ``let`` blocks. The following code
|
||||||
|
won't compile:
|
||||||
|
|
||||||
|
.. code-block:: nimrod
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
var
|
||||||
|
path = "usr/local/nimrodc.html"
|
||||||
|
dir, name, ext = ""
|
||||||
|
|
||||||
|
(dir, name, ext) = splitFile(path)
|
||||||
|
# --> Error: '(dir, name, ext)' cannot be assigned to
|
||||||
|
|
||||||
|
|
||||||
Reference and pointer types
|
Reference and pointer types
|
||||||
---------------------------
|
---------------------------
|
||||||
|
|
@ -1547,7 +1595,7 @@ exported symbols. An alternative that only imports listed symbols is the
|
||||||
|
|
||||||
Include statement
|
Include statement
|
||||||
-----------------
|
-----------------
|
||||||
The `include`:idx: statement does something fundametally different than
|
The `include`:idx: statement does something fundamentally different than
|
||||||
importing a module: it merely includes the contents of a file. The ``include``
|
importing a module: it merely includes the contents of a file. The ``include``
|
||||||
statement is useful to split up a large module into several files:
|
statement is useful to split up a large module into several files:
|
||||||
|
|
||||||
|
|
|
||||||
267
doc/tut2.txt
267
doc/tut2.txt
|
|
@ -699,15 +699,22 @@ once.
|
||||||
Macros
|
Macros
|
||||||
======
|
======
|
||||||
|
|
||||||
Macros enable advanced compile-time code transformations, but they
|
Macros enable advanced compile-time code transformations, but they cannot
|
||||||
cannot change Nimrod's syntax. However, this is no real restriction because
|
change Nimrod's syntax. However, this is no real restriction because Nimrod's
|
||||||
Nimrod's syntax is flexible enough anyway.
|
syntax is flexible enough anyway. Macros have to be implemented in pure Nimrod
|
||||||
|
code if `foreign function interface (FFI)
|
||||||
|
<manual.html#foreign-function-interface>`_ is not enabled in the compiler, but
|
||||||
|
other than that restriction (which at some point in the future will go away)
|
||||||
|
you can write any kind of Nimrod code and the compiler will run it at compile
|
||||||
|
time.
|
||||||
|
|
||||||
To write a macro, one needs to know how the Nimrod concrete syntax is converted
|
There are two ways to write a macro, either *generating* Nimrod source code and
|
||||||
to an abstract syntax tree (AST). The AST is documented in the
|
letting the compiler parse it, or creating manually an abstract syntax tree
|
||||||
`macros <macros.html>`_ module.
|
(AST) which you feed to the compiler. In order to build the AST one needs to
|
||||||
|
know how the Nimrod concrete syntax is converted to an abstract syntax tree
|
||||||
|
(AST). The AST is documented in the `macros <macros.html>`_ module.
|
||||||
|
|
||||||
There are two ways to invoke a macro:
|
Once your macro is finished, there are two ways to invoke it:
|
||||||
(1) invoking a macro like a procedure call (`expression macros`:idx:)
|
(1) invoking a macro like a procedure call (`expression macros`:idx:)
|
||||||
(2) invoking a macro with the special ``macrostmt``
|
(2) invoking a macro with the special ``macrostmt``
|
||||||
syntax (`statement macros`:idx:)
|
syntax (`statement macros`:idx:)
|
||||||
|
|
@ -796,3 +803,249 @@ Term rewriting macros
|
||||||
Term rewriting macros can be used to enhance the compilation process
|
Term rewriting macros can be used to enhance the compilation process
|
||||||
with user defined optimizations; see this `document <trmacros.html>`_ for
|
with user defined optimizations; see this `document <trmacros.html>`_ for
|
||||||
further information.
|
further information.
|
||||||
|
|
||||||
|
|
||||||
|
Building your first macro
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
To give a footstart to writing macros we will show now how to turn your typical
|
||||||
|
dynamic code into something that compiles statically. For the exercise we will
|
||||||
|
use the following snippet of code as the starting point:
|
||||||
|
|
||||||
|
.. code-block:: nimrod
|
||||||
|
|
||||||
|
import strutils, tables
|
||||||
|
|
||||||
|
proc readCfgAtRuntime(cfgFilename: string): TTable[string, string] =
|
||||||
|
let
|
||||||
|
inputString = readFile(cfgFilename)
|
||||||
|
var
|
||||||
|
source = ""
|
||||||
|
|
||||||
|
result = initTable[string, string]()
|
||||||
|
for line in inputString.splitLines:
|
||||||
|
# Ignore empty lines
|
||||||
|
if line.len < 1: continue
|
||||||
|
var chunks = split(line, ',')
|
||||||
|
if chunks.len != 2:
|
||||||
|
quit("Input needs comma split values, got: " & line)
|
||||||
|
result[chunks[0]] = chunks[1]
|
||||||
|
|
||||||
|
if result.len < 1: quit("Input file empty!")
|
||||||
|
|
||||||
|
let info = readCfgAtRuntime("data.cfg")
|
||||||
|
|
||||||
|
when isMainModule:
|
||||||
|
echo info["licenseOwner"]
|
||||||
|
echo info["licenseKey"]
|
||||||
|
echo info["version"]
|
||||||
|
|
||||||
|
Presumably this snippet of code could be used in a commercial software, reading
|
||||||
|
a configuration file to display information about the person who bought the
|
||||||
|
software. This external file would be generated by an online web shopping cart
|
||||||
|
to be included along the program containing the license information::
|
||||||
|
|
||||||
|
version,1.1
|
||||||
|
licenseOwner,Hyori Lee
|
||||||
|
licenseKey,M1Tl3PjBWO2CC48m
|
||||||
|
|
||||||
|
The ``readCfgAtRuntime`` proc will open the given filename and return a
|
||||||
|
``TTable`` from the `tables module <tables.html>`_. The parsing of the file is
|
||||||
|
done (without much care for handling invalid data or corner cases) using the
|
||||||
|
``split`` proc from the `strutils module <strutils.html>`_. There are many
|
||||||
|
things which can fail; mind the purpose is explaining how to make this run at
|
||||||
|
compile time, not how to properly implement a DRM scheme.
|
||||||
|
|
||||||
|
The reimplementation of this code as a compile time proc will allow us to get
|
||||||
|
rid of the ``data.cfg`` file we would need to distribute along the binary, plus
|
||||||
|
if the information is really constant, it doesn't make from a logical point of
|
||||||
|
view to have it *mutable* in a global variable, it would be better if it was a
|
||||||
|
constant. Finally, and likely the most valuable feature, we can implement some
|
||||||
|
verification at compile time. You could think of this as a *better unit
|
||||||
|
testing*, since it is impossible to obtain a binary unless everything is
|
||||||
|
correct, preventing you to ship to users a broken program which won't start
|
||||||
|
because a small critical file is missing or its contents changed by mistake to
|
||||||
|
something invalid.
|
||||||
|
|
||||||
|
|
||||||
|
Generating source code
|
||||||
|
++++++++++++++++++++++
|
||||||
|
|
||||||
|
Our first attempt will start by modifying the program to generate a compile
|
||||||
|
time string with the *generated source code*, which we then pass to the
|
||||||
|
``parseStmt`` proc from the `macros module <macros.html>`_. Here is the
|
||||||
|
modified source code implementing the macro:
|
||||||
|
|
||||||
|
.. code-block:: nimrod
|
||||||
|
import macros, strutils
|
||||||
|
|
||||||
|
macro readCfgAndBuildSource(cfgFilename: string): stmt =
|
||||||
|
let
|
||||||
|
inputString = slurp(cfgFilename.strVal)
|
||||||
|
var
|
||||||
|
source = ""
|
||||||
|
|
||||||
|
for line in inputString.splitLines:
|
||||||
|
# Ignore empty lines
|
||||||
|
if line.len < 1: continue
|
||||||
|
var chunks = split(line, ',')
|
||||||
|
if chunks.len != 2:
|
||||||
|
error("Input needs comma split values, got: " & line)
|
||||||
|
source &= "const cfg" & chunks[0] & "= \"" & chunks[1] & "\"\n"
|
||||||
|
|
||||||
|
if source.len < 1: error("Input file empty!")
|
||||||
|
result = parseStmt(source)
|
||||||
|
|
||||||
|
readCfgAndBuildSource("data.cfg")
|
||||||
|
|
||||||
|
when isMainModule:
|
||||||
|
echo cfglicenseOwner
|
||||||
|
echo cfglicenseKey
|
||||||
|
echo cfgversion
|
||||||
|
|
||||||
|
The good news is not much has changed! First, we need to change the handling of
|
||||||
|
the input parameter. In the dynamic version the ``readCfgAtRuntime`` proc
|
||||||
|
receives a string parameter. However, in the macro version it is also declared
|
||||||
|
as string, but this is the *outside* interface of the macro. When the macro is
|
||||||
|
run, it actually gets a ``PNimrodNode`` object instead of a string, and we have
|
||||||
|
to call the ``strVal`` proc from the `macros module <macros.html>`_ to obtain
|
||||||
|
the string being passed in to the macro.
|
||||||
|
|
||||||
|
Second, we cannot use the ``readFile`` proc from the `system module
|
||||||
|
<system.html>`_ due to FFI restriction at compile time. If we try to use this
|
||||||
|
proc, or any other which depends on FFI, the compiler will error with the
|
||||||
|
message ``cannot evaluate`` and a dump of the macro's source code, along with a
|
||||||
|
stack trace where the compiler reached before bailing out. We can get around
|
||||||
|
this limitation by using the ``slurp`` proc from the `system module
|
||||||
|
<system.html>`_, which was precisely made for compilation time (just like
|
||||||
|
``gorge`` which executes an external program and captures its output).
|
||||||
|
|
||||||
|
The interesting thing is that our macro does not return a runtime ``TTable``
|
||||||
|
object. Instead, it builds up Nimrod source code into the ``source`` variable.
|
||||||
|
For each line of the configuration file a ``const`` variable will be generated.
|
||||||
|
To avoid conflicts we prefix these variables with ``cfg``. In essence, what the
|
||||||
|
compiler is doing is replacing the line calling the macro with the following
|
||||||
|
snippet of code:
|
||||||
|
|
||||||
|
.. code-block:: nimrod
|
||||||
|
const cfgversion= "1.1"
|
||||||
|
const cfglicenseOwner= "Hyori Lee"
|
||||||
|
const cfglicenseKey= "M1Tl3PjBWO2CC48m"
|
||||||
|
|
||||||
|
You can verify this yourself adding the line ``echo source`` somewhere at the
|
||||||
|
end of the macro and compiling the program. Another difference is that instead
|
||||||
|
of calling the usual ``quit`` proc to abort (which we could still call) this
|
||||||
|
version calls the ``error`` proc. The ``error`` proc has the same behavior as
|
||||||
|
``quit`` but will dump also the source and file line information where the
|
||||||
|
error happened, making it easier for the programmer to find where compilation
|
||||||
|
failed. In this situation it would point to the line invoking the macro, but
|
||||||
|
**not** the line of ``data.cfg`` we are processing, that's something the macro
|
||||||
|
itself would need to control.
|
||||||
|
|
||||||
|
|
||||||
|
Generating AST by hand
|
||||||
|
++++++++++++++++++++++
|
||||||
|
|
||||||
|
To generate an AST we would need to intimately know the structures used by the
|
||||||
|
Nimrod compiler exposed in the `macros module <macros.html>`_, which at first
|
||||||
|
look seems a daunting task. But we can use a helper shortcut the ``dumpTree``
|
||||||
|
macro, which is used as a statement macro instead of an expression macro.
|
||||||
|
Since we know that we want to generate a bunch of ``const`` symbols we can
|
||||||
|
create the following source file and compile it to see what the compiler
|
||||||
|
*expects* from us:
|
||||||
|
|
||||||
|
.. code-block:: nimrod
|
||||||
|
import macros
|
||||||
|
|
||||||
|
dumpTree:
|
||||||
|
const cfgversion: string = "1.1"
|
||||||
|
const cfglicenseOwner= "Hyori Lee"
|
||||||
|
const cfglicenseKey= "M1Tl3PjBWO2CC48m"
|
||||||
|
|
||||||
|
During compilation of the source code we should see the following lines in the
|
||||||
|
output (again, since this is a macro, compilation is enough, you don't have to
|
||||||
|
run any binary)::
|
||||||
|
|
||||||
|
StmtList
|
||||||
|
ConstSection
|
||||||
|
ConstDef
|
||||||
|
Ident !"cfgversion"
|
||||||
|
Ident !"string"
|
||||||
|
StrLit 1.1
|
||||||
|
ConstSection
|
||||||
|
ConstDef
|
||||||
|
Ident !"cfglicenseOwner"
|
||||||
|
Empty
|
||||||
|
StrLit Hyori Lee
|
||||||
|
ConstSection
|
||||||
|
ConstDef
|
||||||
|
Ident !"cfglicenseKey"
|
||||||
|
Empty
|
||||||
|
StrLit M1Tl3PjBWO2CC48m
|
||||||
|
|
||||||
|
With this output we have a better idea of what kind of input the compiler
|
||||||
|
expects. We need to generate a list of statements. For each constant the source
|
||||||
|
code generates a ``ConstSection`` and a ``ConstDef``. If we were to move all
|
||||||
|
the constants to a single ``const`` block we would see only a single
|
||||||
|
``ConstSection`` with three children.
|
||||||
|
|
||||||
|
Maybe you didn't notice, but in the ``dumpTree`` example the first constant
|
||||||
|
explicitly specifies the type of the constant. That's why in the tree output
|
||||||
|
the two last constants have their second child ``Empty`` but the first has a
|
||||||
|
string identifier. So basically a ``const`` definition is made up from an
|
||||||
|
identifier, optionally a type (can be an *empty* node) and the value. Armed
|
||||||
|
with this knowledge, let's look at the finished version of the AST building
|
||||||
|
macro:
|
||||||
|
|
||||||
|
.. code-block:: nimrod
|
||||||
|
import macros, strutils
|
||||||
|
|
||||||
|
macro readCfgAndBuildAST(cfgFilename: string): stmt =
|
||||||
|
let
|
||||||
|
inputString = slurp(cfgFilename.strVal)
|
||||||
|
|
||||||
|
result = newNimNode(nnkStmtList)
|
||||||
|
for line in inputString.splitLines:
|
||||||
|
# Ignore empty lines
|
||||||
|
if line.len < 1: continue
|
||||||
|
var chunks = split(line, ',')
|
||||||
|
if chunks.len != 2:
|
||||||
|
error("Input needs comma split values, got: " & line)
|
||||||
|
var
|
||||||
|
section = newNimNode(nnkConstSection)
|
||||||
|
constDef = newNimNode(nnkConstDef)
|
||||||
|
constDef.add(newIdentNode("cfg" & chunks[0]))
|
||||||
|
constDef.add(newEmptyNode())
|
||||||
|
constDef.add(newStrLitNode(chunks[1]))
|
||||||
|
section.add(constDef)
|
||||||
|
result.add(section)
|
||||||
|
|
||||||
|
if result.len < 1: error("Input file empty!")
|
||||||
|
|
||||||
|
readCfgAndBuildAST("data.cfg")
|
||||||
|
|
||||||
|
when isMainModule:
|
||||||
|
echo cfglicenseOwner
|
||||||
|
echo cfglicenseKey
|
||||||
|
echo cfgversion
|
||||||
|
|
||||||
|
Since we are building on the previous example generating source code, we will
|
||||||
|
only mention the differences to it. Instead of creating a temporary ``string``
|
||||||
|
variable and writing into it source code as if it were written *by hand*, we
|
||||||
|
use the ``result`` variable directly and create a statement list node
|
||||||
|
(``nnkStmtList``) which will hold our children.
|
||||||
|
|
||||||
|
For each input line we have to create a constant definition (``nnkConstDef``)
|
||||||
|
and wrap it inside a constant section (``nnkConstSection``). Once these
|
||||||
|
variables are created, we fill them hierarchichally like the previous AST dump
|
||||||
|
tree showed: the constant definition is a child of the section definition, and
|
||||||
|
the constant definition has an identifier node, an empty node (we let the
|
||||||
|
compiler figure out the type), and a string literal with the value.
|
||||||
|
|
||||||
|
A last tip when writing a macro: if you are not sure the AST you are building
|
||||||
|
looks ok, you may be tempted to use the ``dumpTree`` macro. But you can't use
|
||||||
|
it *inside* the macro you are writting/debugging. Instead ``echo`` the string
|
||||||
|
generated by ``treeRepr``. If at the end of the this example you add ``echo
|
||||||
|
treeRepr(result)`` you should get the same output as using the ``dumpTree``
|
||||||
|
macro, but of course you can call that at any point of the macro where you
|
||||||
|
might be having troubles.
|
||||||
|
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
import cairo
|
|
||||||
|
|
||||||
var surface = image_surface_create(FORMAT_ARGB32, 240, 80)
|
|
||||||
var cr = create(surface)
|
|
||||||
|
|
||||||
select_font_face(cr, "serif", FONT_SLANT_NORMAL,
|
|
||||||
FONT_WEIGHT_BOLD)
|
|
||||||
set_font_size(cr, 32.0)
|
|
||||||
set_source_rgb(cr, 0.0, 0.0, 1.0)
|
|
||||||
move_to(cr, 10.0, 50.0)
|
|
||||||
show_text(cr, "Hello, world")
|
|
||||||
destroy(cr)
|
|
||||||
discard write_to_png(surface, "hello.png")
|
|
||||||
destroy(surface)
|
|
||||||
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
import
|
|
||||||
cairo, glib2, gtk2
|
|
||||||
|
|
||||||
proc destroy(widget: pWidget, data: pgpointer) {.cdecl.} =
|
|
||||||
main_quit()
|
|
||||||
|
|
||||||
var
|
|
||||||
window: pWidget
|
|
||||||
nimrod_init()
|
|
||||||
window = window_new(WINDOW_TOPLEVEL)
|
|
||||||
discard signal_connect(window, "destroy",
|
|
||||||
SIGNAL_FUNC(ex1.destroy), nil)
|
|
||||||
show(window)
|
|
||||||
main()
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
|
|
||||||
import
|
|
||||||
glib2, gtk2
|
|
||||||
|
|
||||||
proc destroy(widget: pWidget, data: pgpointer){.cdecl.} =
|
|
||||||
main_quit()
|
|
||||||
|
|
||||||
var
|
|
||||||
window: PWidget
|
|
||||||
button: PWidget
|
|
||||||
|
|
||||||
nimrod_init()
|
|
||||||
window = window_new(WINDOW_TOPLEVEL)
|
|
||||||
button = button_new("Click me")
|
|
||||||
set_border_width(PContainer(Window), 5)
|
|
||||||
add(PContainer(window), button)
|
|
||||||
discard signal_connect(window, "destroy",
|
|
||||||
SIGNAL_FUNC(ex2.destroy), nil)
|
|
||||||
show(button)
|
|
||||||
show(window)
|
|
||||||
main()
|
|
||||||
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
|
|
||||||
import
|
|
||||||
glib2, gtk2
|
|
||||||
|
|
||||||
proc newbutton(ALabel: cstring): PWidget =
|
|
||||||
Result = button_new(ALabel)
|
|
||||||
show(result)
|
|
||||||
|
|
||||||
proc destroy(widget: pWidget, data: pgpointer){.cdecl.} =
|
|
||||||
main_quit()
|
|
||||||
|
|
||||||
nimrod_init()
|
|
||||||
var window = window_new(WINDOW_TOPLEVEL) # Box to divide window in 2 halves:
|
|
||||||
var totalbox = vbox_new(true, 10)
|
|
||||||
show(totalbox) # A box for each half of the screen:
|
|
||||||
var hbox = hbox_new(false, 5)
|
|
||||||
show(hbox)
|
|
||||||
var vbox = vbox_new(true, 5)
|
|
||||||
show(vbox) # Put boxes in their halves
|
|
||||||
pack_start(totalbox, hbox, true, true, 0)
|
|
||||||
pack_start(totalbox, vbox, true, true, 0) # Now fill boxes with buttons.
|
|
||||||
|
|
||||||
pack_start(hbox, newbutton("Button 1"), false, false, 0)
|
|
||||||
pack_start(hbox, newbutton("Button 2"), false, false, 0)
|
|
||||||
pack_start(hbox, newbutton("Button 3"), false, false, 0) # Vertical box
|
|
||||||
pack_start(vbox, newbutton("Button A"), true, true, 0)
|
|
||||||
pack_start(vbox, newbutton("Button B"), true, true, 0)
|
|
||||||
pack_start(vbox, newbutton("Button C"), true, true, 0) # Put totalbox in window
|
|
||||||
set_border_width(PCONTAINER(Window), 5)
|
|
||||||
add(PContainer(window), totalbox)
|
|
||||||
discard signal_connect(window, "destroy", SIGNAL_FUNC(ex3.destroy), nil)
|
|
||||||
show(window)
|
|
||||||
main()
|
|
||||||
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
|
|
||||||
import
|
|
||||||
glib2, gtk2
|
|
||||||
|
|
||||||
proc newbutton(ALabel: cstring): PWidget =
|
|
||||||
Result = button_new(ALabel)
|
|
||||||
show(result)
|
|
||||||
|
|
||||||
proc destroy(widget: pWidget, data: pgpointer){.cdecl.} =
|
|
||||||
main_quit()
|
|
||||||
|
|
||||||
nimrod_init()
|
|
||||||
var window = window_new(WINDOW_TOPLEVEL)
|
|
||||||
var Maintable = table_new(6, 6, True)
|
|
||||||
|
|
||||||
proc AddToTable(Widget: PWidget, Left, Right, Top, Bottom: guint) =
|
|
||||||
attach_defaults(MainTable, Widget, Left, right, top, bottom)
|
|
||||||
|
|
||||||
show(MainTable)
|
|
||||||
AddToTable(newbutton("1,1 At 1,1"), 1, 2, 1, 2)
|
|
||||||
AddToTable(newbutton("2,2 At 3,1"), 3, 5, 1, 3)
|
|
||||||
AddToTable(newbutton("4,1 At 4,1"), 1, 5, 4, 5) # Put all in window
|
|
||||||
set_border_width(Window, 5)
|
|
||||||
add(window, maintable)
|
|
||||||
discard signal_connect(window, "destroy",
|
|
||||||
SignalFunc(ex4.destroy), nil)
|
|
||||||
show(window)
|
|
||||||
main()
|
|
||||||
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
|
|
||||||
import
|
|
||||||
glib2, gtk2
|
|
||||||
|
|
||||||
proc destroy(widget: pWidget, data: pgpointer){.cdecl.} =
|
|
||||||
main_quit()
|
|
||||||
|
|
||||||
proc widgetDestroy(w: PWidget) {.cdecl.} =
|
|
||||||
destroy(w)
|
|
||||||
|
|
||||||
nimrod_init()
|
|
||||||
var window = window_new(WINDOW_TOPLEVEL)
|
|
||||||
var button = button_new("Click me")
|
|
||||||
set_border_width(Window, 5)
|
|
||||||
add(window, button)
|
|
||||||
discard signal_connect(window, "destroy",
|
|
||||||
SIGNAL_FUNC(ex5.destroy), nil)
|
|
||||||
discard signal_connect_object(button, "clicked",
|
|
||||||
SIGNAL_FUNC(widgetDestroy),
|
|
||||||
window)
|
|
||||||
show(button)
|
|
||||||
show(window)
|
|
||||||
main()
|
|
||||||
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
|
|
||||||
import
|
|
||||||
glib2, gtk2
|
|
||||||
|
|
||||||
type
|
|
||||||
TButtonSignalState = object
|
|
||||||
Obj: gtk2.PObject
|
|
||||||
SignalID: int32
|
|
||||||
Disable: bool
|
|
||||||
|
|
||||||
PButtonSignalState = ptr TButtonSignalState
|
|
||||||
|
|
||||||
proc destroy(widget: pWidget, data: pgpointer){.cdecl.} =
|
|
||||||
main_quit()
|
|
||||||
|
|
||||||
proc widgetDestroy(w: PWidget) {.cdecl.} = destroy(w)
|
|
||||||
|
|
||||||
proc disablesignal(widget: pWidget, data: pgpointer){.cdecl.} =
|
|
||||||
var s = cast[PButtonSignalState](Data)
|
|
||||||
if s.Disable:
|
|
||||||
signal_handler_block(s.Obj, s.SignalID)
|
|
||||||
else:
|
|
||||||
signal_handler_unblock(s.Obj, s.SignalID)
|
|
||||||
s.disable = not s.disable
|
|
||||||
|
|
||||||
var
|
|
||||||
QuitState: TButtonSignalState
|
|
||||||
|
|
||||||
nimrod_init()
|
|
||||||
var window = window_new(WINDOW_TOPLEVEL)
|
|
||||||
var quitbutton = button_new("Quit program")
|
|
||||||
var disablebutton = button_new("Disable button")
|
|
||||||
var windowbox = vbox_new(TRUE, 10)
|
|
||||||
pack_start(windowbox, disablebutton, True, false, 0)
|
|
||||||
pack_start(windowbox, quitbutton, True, false, 0)
|
|
||||||
set_border_width(Window, 10)
|
|
||||||
add(window, windowbox)
|
|
||||||
discard signal_connect(window, "destroy", SIGNAL_FUNC(ex6.destroy), nil)
|
|
||||||
QuitState.Obj = QuitButton
|
|
||||||
quitState.SignalID = signal_connect_object(QuitState.Obj, "clicked",
|
|
||||||
SIGNAL_FUNC(widgetDestroy), window).int32
|
|
||||||
QuitState.Disable = True
|
|
||||||
discard signal_connect(disablebutton, "clicked",
|
|
||||||
SIGNAL_FUNC(disablesignal), addr(QuitState))
|
|
||||||
show(quitbutton)
|
|
||||||
show(disablebutton)
|
|
||||||
show(windowbox)
|
|
||||||
show(window)
|
|
||||||
main()
|
|
||||||
|
|
||||||
|
|
@ -1,46 +0,0 @@
|
||||||
|
|
||||||
import
|
|
||||||
gdk2, glib2, gtk2
|
|
||||||
|
|
||||||
proc destroy(widget: pWidget, data: pgpointer){.cdecl.} =
|
|
||||||
main_quit()
|
|
||||||
|
|
||||||
const
|
|
||||||
Inside: cstring = "Mouse is over label"
|
|
||||||
OutSide: cstring = "Mouse is not over label"
|
|
||||||
|
|
||||||
var
|
|
||||||
OverLabel: bool
|
|
||||||
|
|
||||||
nimrod_init()
|
|
||||||
var window = window_new(gtk2.WINDOW_TOPLEVEL)
|
|
||||||
var stackbox = vbox_new(TRUE, 10)
|
|
||||||
var box1 = event_box_new()
|
|
||||||
var label1 = label_new("Move mouse over label")
|
|
||||||
add(box1, label1)
|
|
||||||
var box2 = event_box_new()
|
|
||||||
var label2 = label_new(OutSide)
|
|
||||||
add(box2, label2)
|
|
||||||
pack_start(stackbox, box1, TRUE, TRUE, 0)
|
|
||||||
pack_start(stackbox, box2, TRUE, TRUE, 0)
|
|
||||||
set_border_width(Window, 5)
|
|
||||||
add(window, stackbox)
|
|
||||||
discard signal_connect(window, "destroy",
|
|
||||||
SIGNAL_FUNC(ex7.destroy), nil)
|
|
||||||
overlabel = False
|
|
||||||
|
|
||||||
|
|
||||||
proc ChangeLabel(P: PWidget, Event: gdk2.PEventCrossing,
|
|
||||||
Data: var bool){.cdecl.} =
|
|
||||||
if not Data: set_text(Label1, Inside)
|
|
||||||
else: set_text(Label2, Outside)
|
|
||||||
Data = not Data
|
|
||||||
|
|
||||||
|
|
||||||
discard signal_connect(box1, "enter_notify_event",
|
|
||||||
SIGNAL_FUNC(ChangeLabel), addr(Overlabel))
|
|
||||||
discard signal_connect(box1, "leave_notify_event",
|
|
||||||
SIGNAL_FUNC(ChangeLabel), addr(Overlabel))
|
|
||||||
show_all(window)
|
|
||||||
main()
|
|
||||||
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
|
|
||||||
import
|
|
||||||
glib2, gtk2
|
|
||||||
|
|
||||||
proc destroy(widget: pWidget, data: pgpointer){.cdecl.} =
|
|
||||||
main_quit()
|
|
||||||
|
|
||||||
nimrod_init()
|
|
||||||
var window = window_new(WINDOW_TOPLEVEL)
|
|
||||||
var stackbox = vbox_new(TRUE, 10)
|
|
||||||
var label1 = label_new("Red label text")
|
|
||||||
var labelstyle = copy(get_style(label1))
|
|
||||||
LabelStyle.fg[STATE_NORMAL].pixel = 0
|
|
||||||
LabelStyle.fg[STATE_NORMAL].red = -1'i16
|
|
||||||
LabelStyle.fg[STATE_NORMAL].blue = 0'i16
|
|
||||||
LabelStyle.fg[STATE_NORMAL].green = 0'i16
|
|
||||||
set_style(label1, labelstyle)
|
|
||||||
# Uncomment this to see the effect of setting the default style.
|
|
||||||
# set_default_style(labelstyle)
|
|
||||||
var label2 = label_new("Black label text")
|
|
||||||
pack_start(stackbox, label1, TRUE, TRUE, 0)
|
|
||||||
pack_start(stackbox, label2, TRUE, TRUE, 0)
|
|
||||||
set_border_width(Window, 5)
|
|
||||||
add(window, stackbox)
|
|
||||||
discard signal_connect(window, "destroy",
|
|
||||||
SIGNAL_FUNC(ex8.destroy), nil)
|
|
||||||
show_all(window)
|
|
||||||
main()
|
|
||||||
|
|
||||||
|
|
@ -1,49 +0,0 @@
|
||||||
|
|
||||||
import
|
|
||||||
gdk2, glib2, gtk2
|
|
||||||
|
|
||||||
proc destroy(widget: pWidget, data: pgpointer){.cdecl.} =
|
|
||||||
main_quit()
|
|
||||||
|
|
||||||
const
|
|
||||||
Inside: cstring = "Mouse is over label"
|
|
||||||
OutSide: cstring = "Mouse is not over label"
|
|
||||||
|
|
||||||
var
|
|
||||||
OverButton: bool
|
|
||||||
|
|
||||||
nimrod_init()
|
|
||||||
var window = window_new(gtk2.WINDOW_TOPLEVEL)
|
|
||||||
var stackbox = vbox_new(TRUE, 10)
|
|
||||||
var button1 = button_new("Move mouse over button")
|
|
||||||
var buttonstyle = copy(get_style(Button1))
|
|
||||||
ButtonStyle.bg[STATE_PRELIGHT].pixel = 0
|
|
||||||
ButtonStyle.bg[STATE_PRELIGHT].red = -1'i16
|
|
||||||
ButtonStyle.bg[STATE_PRELIGHT].blue = 0'i16
|
|
||||||
ButtonStyle.bg[STATE_PRELIGHT].green = 0'i16
|
|
||||||
set_style(button1, buttonstyle)
|
|
||||||
var button2 = button_new()
|
|
||||||
var ALabel = label_new(Outside)
|
|
||||||
|
|
||||||
|
|
||||||
proc ChangeLabel(P: PWidget, Event: gdk2.PEventCrossing,
|
|
||||||
Data: var bool){.cdecl.} =
|
|
||||||
if Not Data: set_text(ALabel, Inside)
|
|
||||||
else: set_text(ALabel, Outside)
|
|
||||||
Data = Not Data
|
|
||||||
|
|
||||||
|
|
||||||
add(button2, ALAbel)
|
|
||||||
pack_start(stackbox, button1, TRUE, TRUE, 0)
|
|
||||||
pack_start(stackbox, button2, TRUE, TRUE, 0)
|
|
||||||
set_border_width(Window, 5)
|
|
||||||
add(window, stackbox)
|
|
||||||
discard signal_connect(window, "destroy",
|
|
||||||
SIGNAL_FUNC(ex9.destroy), nil)
|
|
||||||
overbutton = False
|
|
||||||
discard signal_connect(button1, "enter_notify_event",
|
|
||||||
SIGNAL_FUNC(ChangeLabel), addr(OverButton))
|
|
||||||
discard signal_connect(button1, "leave_notify_event",
|
|
||||||
SIGNAL_FUNC(ChangeLabel), addr(OverButton))
|
|
||||||
show_all(window)
|
|
||||||
main()
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
# Embedds Lua into a Nimrod application
|
|
||||||
|
|
||||||
import
|
|
||||||
lua, lualib, lauxlib
|
|
||||||
|
|
||||||
const
|
|
||||||
code = """
|
|
||||||
print 'hi'
|
|
||||||
"""
|
|
||||||
|
|
||||||
var L = newstate()
|
|
||||||
openlibs(L)
|
|
||||||
discard loadbuffer(L, code, code.len, "line")
|
|
||||||
discard pcall(L, 0, 0, 0)
|
|
||||||
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
# Example to embed Python into your application
|
|
||||||
|
|
||||||
import python
|
|
||||||
|
|
||||||
# IMPORTANT: Python on Windows does not like CR characters, so
|
|
||||||
# we use only \L here.
|
|
||||||
|
|
||||||
Py_Initialize()
|
|
||||||
discard PyRun_SimpleString("from time import time,ctime\L" &
|
|
||||||
"print 'Today is',ctime(time())\L")
|
|
||||||
Py_Finalize()
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
# Example to embed TCL in Nimrod
|
|
||||||
|
|
||||||
import tcl, os
|
|
||||||
|
|
||||||
const
|
|
||||||
myScript = """puts "Hello, World - In quotes" """
|
|
||||||
myScript2 = """
|
|
||||||
package require Tk
|
|
||||||
pack [entry .e -textvar e -width 50]
|
|
||||||
bind .e <Return> {
|
|
||||||
set e [regsub { *=.*} $e ""] ;# remove evaluation (Chris)
|
|
||||||
catch {expr [string map {/ *1./} $e]} res
|
|
||||||
append e " = $res"
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
|
|
||||||
FindExecutable(getAppFilename())
|
|
||||||
var interp = CreateInterp()
|
|
||||||
if interp == nil: quit("cannot create TCL interpreter")
|
|
||||||
if Init(interp) != TCL_OK:
|
|
||||||
quit("cannot init interpreter")
|
|
||||||
if tcl.Eval(interp, myScript) != TCL_OK:
|
|
||||||
quit("cannot execute script.tcl")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
# test a Windows GUI application
|
|
||||||
|
|
||||||
import
|
|
||||||
windows, shellapi, nb30, mmsystem, shfolder
|
|
||||||
|
|
||||||
#proc MessageBox(hWnd: int, lpText, lpCaption: CString, uType: uint): int
|
|
||||||
# {stdcall, import: "MessageBox", header: "<windows.h>"}
|
|
||||||
|
|
||||||
discard MessageBox(0, "Hello World!", "Nimrod GUI Application", 0)
|
|
||||||
|
|
@ -1,71 +0,0 @@
|
||||||
import xlib, xutil, x, keysym
|
|
||||||
|
|
||||||
const
|
|
||||||
WINDOW_WIDTH = 400
|
|
||||||
WINDOW_HEIGHT = 300
|
|
||||||
|
|
||||||
var
|
|
||||||
width, height: cuint
|
|
||||||
display: PDisplay
|
|
||||||
screen: cint
|
|
||||||
depth: int
|
|
||||||
win: TWindow
|
|
||||||
sizeHints: TXSizeHints
|
|
||||||
|
|
||||||
proc create_window =
|
|
||||||
width = WINDOW_WIDTH
|
|
||||||
height = WINDOW_HEIGHT
|
|
||||||
|
|
||||||
display = XOpenDisplay(nil)
|
|
||||||
if display == nil:
|
|
||||||
echo("Verbindung zum X-Server fehlgeschlagen")
|
|
||||||
quit(1)
|
|
||||||
|
|
||||||
screen = XDefaultScreen(display)
|
|
||||||
depth = XDefaultDepth(display, screen)
|
|
||||||
var rootwin = XRootWindow(display, screen)
|
|
||||||
win = XCreateSimpleWindow(display, rootwin, 100, 10,
|
|
||||||
width, height, 5,
|
|
||||||
XBlackPixel(display, screen),
|
|
||||||
XWhitePixel(display, screen))
|
|
||||||
size_hints.flags = PSize or PMinSize or PMaxSize
|
|
||||||
size_hints.min_width = width.cint
|
|
||||||
size_hints.max_width = width.cint
|
|
||||||
size_hints.min_height = height.cint
|
|
||||||
size_hints.max_height = height.cint
|
|
||||||
discard XSetStandardProperties(display, win, "Simple Window", "window",
|
|
||||||
0, nil, 0, addr(size_hints))
|
|
||||||
discard XSelectInput(display, win, ButtonPressMask or KeyPressMask or
|
|
||||||
PointerMotionMask)
|
|
||||||
discard XMapWindow(display, win)
|
|
||||||
|
|
||||||
proc close_window =
|
|
||||||
discard XDestroyWindow(display, win)
|
|
||||||
discard XCloseDisplay(display)
|
|
||||||
|
|
||||||
var
|
|
||||||
xev: TXEvent
|
|
||||||
|
|
||||||
proc process_event =
|
|
||||||
var key: TKeySym
|
|
||||||
case int(xev.theType)
|
|
||||||
of KeyPress:
|
|
||||||
key = XLookupKeysym(cast[ptr TXKeyEvent](addr(xev)), 0)
|
|
||||||
if key.int != 0:
|
|
||||||
echo("keyboard event")
|
|
||||||
of ButtonPressMask, PointerMotionMask:
|
|
||||||
Echo("Mouse event")
|
|
||||||
else: nil
|
|
||||||
|
|
||||||
proc eventloop =
|
|
||||||
discard XFlush(display)
|
|
||||||
var num_events = int(XPending(display))
|
|
||||||
while num_events != 0:
|
|
||||||
dec(num_events)
|
|
||||||
discard XNextEvent(display, addr(xev))
|
|
||||||
process_event()
|
|
||||||
|
|
||||||
create_window()
|
|
||||||
while true:
|
|
||||||
eventloop()
|
|
||||||
close_window()
|
|
||||||
|
|
@ -500,7 +500,7 @@ const
|
||||||
|
|
||||||
from strutils import cmpIgnoreStyle, format
|
from strutils import cmpIgnoreStyle, format
|
||||||
|
|
||||||
proc ExpectKind*(n: PNimrodNode; k: set[TNimrodNodeKind]) {.compileTime.} =
|
proc expectKind*(n: PNimrodNode; k: set[TNimrodNodeKind]) {.compileTime.} =
|
||||||
assert n.kind in k, "Expected one of $1, got $2".format(k, n.kind)
|
assert n.kind in k, "Expected one of $1, got $2".format(k, n.kind)
|
||||||
|
|
||||||
proc newProc*(name = newEmptyNode(); params: openarray[PNimrodNode] = [];
|
proc newProc*(name = newEmptyNode(); params: openarray[PNimrodNode] = [];
|
||||||
|
|
|
||||||
|
|
@ -869,6 +869,12 @@ proc parseLine(p: var TRstParser, father: PRstNode) =
|
||||||
of tkWhite, tkWord, tkOther, tkPunct: parseInline(p, father)
|
of tkWhite, tkWord, tkOther, tkPunct: parseInline(p, father)
|
||||||
else: break
|
else: break
|
||||||
|
|
||||||
|
proc parseUntilNewline(p: var TRstParser, father: PRstNode) =
|
||||||
|
while True:
|
||||||
|
case p.tok[p.idx].kind
|
||||||
|
of tkWhite, tkWord, tkAdornment, tkOther, tkPunct: parseInline(p, father)
|
||||||
|
of tkEof, tkIndent: break
|
||||||
|
|
||||||
proc parseSection(p: var TRstParser, result: PRstNode)
|
proc parseSection(p: var TRstParser, result: PRstNode)
|
||||||
proc parseField(p: var TRstParser): PRstNode =
|
proc parseField(p: var TRstParser): PRstNode =
|
||||||
result = newRstNode(rnField)
|
result = newRstNode(rnField)
|
||||||
|
|
@ -1078,7 +1084,7 @@ proc parseParagraph(p: var TRstParser, result: PRstNode) =
|
||||||
|
|
||||||
proc parseHeadline(p: var TRstParser): PRstNode =
|
proc parseHeadline(p: var TRstParser): PRstNode =
|
||||||
result = newRstNode(rnHeadline)
|
result = newRstNode(rnHeadline)
|
||||||
parseLine(p, result)
|
parseUntilNewLine(p, result)
|
||||||
assert(p.tok[p.idx].kind == tkIndent)
|
assert(p.tok[p.idx].kind == tkIndent)
|
||||||
assert(p.tok[p.idx + 1].kind == tkAdornment)
|
assert(p.tok[p.idx + 1].kind == tkAdornment)
|
||||||
var c = p.tok[p.idx + 1].symbol[0]
|
var c = p.tok[p.idx + 1].symbol[0]
|
||||||
|
|
@ -1172,7 +1178,7 @@ proc parseOverline(p: var TRstParser): PRstNode =
|
||||||
inc(p.idx, 2)
|
inc(p.idx, 2)
|
||||||
result = newRstNode(rnOverline)
|
result = newRstNode(rnOverline)
|
||||||
while true:
|
while true:
|
||||||
parseLine(p, result)
|
parseUntilNewline(p, result)
|
||||||
if p.tok[p.idx].kind == tkIndent:
|
if p.tok[p.idx].kind == tkIndent:
|
||||||
inc(p.idx)
|
inc(p.idx)
|
||||||
if p.tok[p.idx - 1].ival > currInd(p):
|
if p.tok[p.idx - 1].ival > currInd(p):
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,8 @@ else:
|
||||||
## A type representing a directory stream.
|
## A type representing a directory stream.
|
||||||
|
|
||||||
type
|
type
|
||||||
|
TSocketHandle* = distinct cint # The type used to represent socket descriptors
|
||||||
|
|
||||||
Tdirent* {.importc: "struct dirent",
|
Tdirent* {.importc: "struct dirent",
|
||||||
header: "<dirent.h>", final, pure.} = object ## dirent_t struct
|
header: "<dirent.h>", final, pure.} = object ## dirent_t struct
|
||||||
d_ino*: TIno ## File serial number.
|
d_ino*: TIno ## File serial number.
|
||||||
|
|
@ -1791,7 +1793,7 @@ proc dlopen*(a1: cstring, a2: cint): pointer {.importc, header: "<dlfcn.h>".}
|
||||||
proc dlsym*(a1: pointer, a2: cstring): pointer {.importc, header: "<dlfcn.h>".}
|
proc dlsym*(a1: pointer, a2: cstring): pointer {.importc, header: "<dlfcn.h>".}
|
||||||
|
|
||||||
proc creat*(a1: cstring, a2: Tmode): cint {.importc, header: "<fcntl.h>".}
|
proc creat*(a1: cstring, a2: Tmode): cint {.importc, header: "<fcntl.h>".}
|
||||||
proc fcntl*(a1: cint, a2: cint): cint {.varargs, importc, header: "<fcntl.h>".}
|
proc fcntl*(a1: cint | TSocketHandle, a2: cint): cint {.varargs, importc, header: "<fcntl.h>".}
|
||||||
proc open*(a1: cstring, a2: cint): cint {.varargs, importc, header: "<fcntl.h>".}
|
proc open*(a1: cstring, a2: cint): cint {.varargs, importc, header: "<fcntl.h>".}
|
||||||
proc posix_fadvise*(a1: cint, a2, a3: Toff, a4: cint): cint {.
|
proc posix_fadvise*(a1: cint, a2, a3: Toff, a4: cint): cint {.
|
||||||
importc, header: "<fcntl.h>".}
|
importc, header: "<fcntl.h>".}
|
||||||
|
|
@ -2068,7 +2070,7 @@ proc access*(a1: cstring, a2: cint): cint {.importc, header: "<unistd.h>".}
|
||||||
proc alarm*(a1: cint): cint {.importc, header: "<unistd.h>".}
|
proc alarm*(a1: cint): cint {.importc, header: "<unistd.h>".}
|
||||||
proc chdir*(a1: cstring): cint {.importc, header: "<unistd.h>".}
|
proc chdir*(a1: cstring): cint {.importc, header: "<unistd.h>".}
|
||||||
proc chown*(a1: cstring, a2: Tuid, a3: Tgid): cint {.importc, header: "<unistd.h>".}
|
proc chown*(a1: cstring, a2: Tuid, a3: Tgid): cint {.importc, header: "<unistd.h>".}
|
||||||
proc close*(a1: cint): cint {.importc, header: "<unistd.h>".}
|
proc close*(a1: cint | TSocketHandle): cint {.importc, header: "<unistd.h>".}
|
||||||
proc confstr*(a1: cint, a2: cstring, a3: int): int {.importc, header: "<unistd.h>".}
|
proc confstr*(a1: cint, a2: cstring, a3: int): int {.importc, header: "<unistd.h>".}
|
||||||
proc crypt*(a1, a2: cstring): cstring {.importc, header: "<unistd.h>".}
|
proc crypt*(a1, a2: cstring): cstring {.importc, header: "<unistd.h>".}
|
||||||
proc ctermid*(a1: cstring): cstring {.importc, header: "<unistd.h>".}
|
proc ctermid*(a1: cstring): cstring {.importc, header: "<unistd.h>".}
|
||||||
|
|
@ -2346,9 +2348,9 @@ proc strerror*(errnum: cint): cstring {.importc, header: "<string.h>".}
|
||||||
proc hstrerror*(herrnum: cint): cstring {.importc, header: "<netdb.h>".}
|
proc hstrerror*(herrnum: cint): cstring {.importc, header: "<netdb.h>".}
|
||||||
|
|
||||||
proc FD_CLR*(a1: cint, a2: var Tfd_set) {.importc, header: "<sys/select.h>".}
|
proc FD_CLR*(a1: cint, a2: var Tfd_set) {.importc, header: "<sys/select.h>".}
|
||||||
proc FD_ISSET*(a1: cint, a2: var Tfd_set): cint {.
|
proc FD_ISSET*(a1: cint | TSocketHandle, a2: var Tfd_set): cint {.
|
||||||
importc, header: "<sys/select.h>".}
|
importc, header: "<sys/select.h>".}
|
||||||
proc FD_SET*(a1: cint, a2: var Tfd_set) {.importc, header: "<sys/select.h>".}
|
proc FD_SET*(a1: cint | TSocketHandle, a2: var Tfd_set) {.importc, header: "<sys/select.h>".}
|
||||||
proc FD_ZERO*(a1: var Tfd_set) {.importc, header: "<sys/select.h>".}
|
proc FD_ZERO*(a1: var Tfd_set) {.importc, header: "<sys/select.h>".}
|
||||||
|
|
||||||
proc pselect*(a1: cint, a2, a3, a4: ptr Tfd_set, a5: ptr ttimespec,
|
proc pselect*(a1: cint, a2, a3, a4: ptr Tfd_set, a5: ptr ttimespec,
|
||||||
|
|
@ -2428,44 +2430,49 @@ proc CMSG_NXTHDR*(mhdr: ptr TMsgHdr, cmsg: ptr TCMsgHdr): ptr TCmsgHdr {.
|
||||||
proc CMSG_FIRSTHDR*(mhdr: ptr TMsgHdr): ptr TCMsgHdr {.
|
proc CMSG_FIRSTHDR*(mhdr: ptr TMsgHdr): ptr TCMsgHdr {.
|
||||||
importc, header: "<sys/socket.h>".}
|
importc, header: "<sys/socket.h>".}
|
||||||
|
|
||||||
proc accept*(a1: cint, a2: ptr Tsockaddr, a3: ptr Tsocklen): cint {.
|
const
|
||||||
|
INVALID_SOCKET* = TSocketHandle(-1)
|
||||||
|
|
||||||
|
proc `==`*(x, y: TSocketHandle): bool {.borrow.}
|
||||||
|
|
||||||
|
proc accept*(a1: TSocketHandle, a2: ptr Tsockaddr, a3: ptr Tsocklen): TSocketHandle {.
|
||||||
importc, header: "<sys/socket.h>".}
|
importc, header: "<sys/socket.h>".}
|
||||||
|
|
||||||
proc bindSocket*(a1: cint, a2: ptr Tsockaddr, a3: Tsocklen): cint {.
|
proc bindSocket*(a1: TSocketHandle, a2: ptr Tsockaddr, a3: Tsocklen): cint {.
|
||||||
importc: "bind", header: "<sys/socket.h>".}
|
importc: "bind", header: "<sys/socket.h>".}
|
||||||
## is Posix's ``bind``, because ``bind`` is a reserved word
|
## is Posix's ``bind``, because ``bind`` is a reserved word
|
||||||
|
|
||||||
proc connect*(a1: cint, a2: ptr Tsockaddr, a3: Tsocklen): cint {.
|
proc connect*(a1: TSocketHandle, a2: ptr Tsockaddr, a3: Tsocklen): cint {.
|
||||||
importc, header: "<sys/socket.h>".}
|
importc, header: "<sys/socket.h>".}
|
||||||
proc getpeername*(a1: cint, a2: ptr Tsockaddr, a3: ptr Tsocklen): cint {.
|
proc getpeername*(a1: TSocketHandle, a2: ptr Tsockaddr, a3: ptr Tsocklen): cint {.
|
||||||
importc, header: "<sys/socket.h>".}
|
importc, header: "<sys/socket.h>".}
|
||||||
proc getsockname*(a1: cint, a2: ptr Tsockaddr, a3: ptr Tsocklen): cint {.
|
proc getsockname*(a1: TSocketHandle, a2: ptr Tsockaddr, a3: ptr Tsocklen): cint {.
|
||||||
importc, header: "<sys/socket.h>".}
|
importc, header: "<sys/socket.h>".}
|
||||||
|
|
||||||
proc getsockopt*(a1, a2, a3: cint, a4: pointer, a5: ptr Tsocklen): cint {.
|
proc getsockopt*(a1: TSocketHandle, a2, a3: cint, a4: pointer, a5: ptr Tsocklen): cint {.
|
||||||
importc, header: "<sys/socket.h>".}
|
importc, header: "<sys/socket.h>".}
|
||||||
|
|
||||||
proc listen*(a1, a2: cint): cint {.
|
proc listen*(a1: TSocketHandle, a2: cint): cint {.
|
||||||
importc, header: "<sys/socket.h>".}
|
importc, header: "<sys/socket.h>".}
|
||||||
proc recv*(a1: cint, a2: pointer, a3: int, a4: cint): int {.
|
proc recv*(a1: TSocketHandle, a2: pointer, a3: int, a4: cint): int {.
|
||||||
importc, header: "<sys/socket.h>".}
|
importc, header: "<sys/socket.h>".}
|
||||||
proc recvfrom*(a1: cint, a2: pointer, a3: int, a4: cint,
|
proc recvfrom*(a1: TSocketHandle, a2: pointer, a3: int, a4: cint,
|
||||||
a5: ptr Tsockaddr, a6: ptr Tsocklen): int {.
|
a5: ptr Tsockaddr, a6: ptr Tsocklen): int {.
|
||||||
importc, header: "<sys/socket.h>".}
|
importc, header: "<sys/socket.h>".}
|
||||||
proc recvmsg*(a1: cint, a2: ptr Tmsghdr, a3: cint): int {.
|
proc recvmsg*(a1: TSocketHandle, a2: ptr Tmsghdr, a3: cint): int {.
|
||||||
importc, header: "<sys/socket.h>".}
|
importc, header: "<sys/socket.h>".}
|
||||||
proc send*(a1: cint, a2: pointer, a3: int, a4: cint): int {.
|
proc send*(a1: TSocketHandle, a2: pointer, a3: int, a4: cint): int {.
|
||||||
importc, header: "<sys/socket.h>".}
|
importc, header: "<sys/socket.h>".}
|
||||||
proc sendmsg*(a1: cint, a2: ptr Tmsghdr, a3: cint): int {.
|
proc sendmsg*(a1: TSocketHandle, a2: ptr Tmsghdr, a3: cint): int {.
|
||||||
importc, header: "<sys/socket.h>".}
|
importc, header: "<sys/socket.h>".}
|
||||||
proc sendto*(a1: cint, a2: pointer, a3: int, a4: cint, a5: ptr Tsockaddr,
|
proc sendto*(a1: TSocketHandle, a2: pointer, a3: int, a4: cint, a5: ptr Tsockaddr,
|
||||||
a6: Tsocklen): int {.
|
a6: Tsocklen): int {.
|
||||||
importc, header: "<sys/socket.h>".}
|
importc, header: "<sys/socket.h>".}
|
||||||
proc setsockopt*(a1, a2, a3: cint, a4: pointer, a5: Tsocklen): cint {.
|
proc setsockopt*(a1: TSocketHandle, a2, a3: cint, a4: pointer, a5: Tsocklen): cint {.
|
||||||
importc, header: "<sys/socket.h>".}
|
importc, header: "<sys/socket.h>".}
|
||||||
proc shutdown*(a1, a2: cint): cint {.
|
proc shutdown*(a1: TSocketHandle, a2: cint): cint {.
|
||||||
importc, header: "<sys/socket.h>".}
|
importc, header: "<sys/socket.h>".}
|
||||||
proc socket*(a1, a2, a3: cint): cint {.
|
proc socket*(a1, a2, a3: cint): TSocketHandle {.
|
||||||
importc, header: "<sys/socket.h>".}
|
importc, header: "<sys/socket.h>".}
|
||||||
proc sockatmark*(a1: cint): cint {.
|
proc sockatmark*(a1: cint): cint {.
|
||||||
importc, header: "<sys/socket.h>".}
|
importc, header: "<sys/socket.h>".}
|
||||||
|
|
|
||||||
|
|
@ -89,13 +89,13 @@ import sockets, os
|
||||||
## getSocket(s).accept(client)
|
## getSocket(s).accept(client)
|
||||||
|
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
from winlean import TTimeVal, TFdSet, FD_ZERO, FD_SET, FD_ISSET, select
|
from winlean import TTimeVal, TSocketHandle, TFdSet, FD_ZERO, FD_SET, FD_ISSET, select
|
||||||
else:
|
else:
|
||||||
from posix import TTimeVal, TFdSet, FD_ZERO, FD_SET, FD_ISSET, select
|
from posix import TTimeVal, TSocketHandle, TFdSet, FD_ZERO, FD_SET, FD_ISSET, select
|
||||||
|
|
||||||
type
|
type
|
||||||
TDelegate* = object
|
TDelegate* = object
|
||||||
fd*: cint
|
fd*: TSocketHandle
|
||||||
deleVal*: PObject
|
deleVal*: PObject
|
||||||
|
|
||||||
handleRead*: proc (h: PObject) {.nimcall.}
|
handleRead*: proc (h: PObject) {.nimcall.}
|
||||||
|
|
@ -213,6 +213,7 @@ proc asyncSockHandleRead(h: PObject) =
|
||||||
else:
|
else:
|
||||||
PAsyncSocket(h).handleAccept(PAsyncSocket(h))
|
PAsyncSocket(h).handleAccept(PAsyncSocket(h))
|
||||||
|
|
||||||
|
proc close*(sock: PAsyncSocket)
|
||||||
proc asyncSockHandleWrite(h: PObject) =
|
proc asyncSockHandleWrite(h: PObject) =
|
||||||
when defined(ssl):
|
when defined(ssl):
|
||||||
if PAsyncSocket(h).socket.isSSL and not
|
if PAsyncSocket(h).socket.isSSL and not
|
||||||
|
|
@ -230,15 +231,19 @@ proc asyncSockHandleWrite(h: PObject) =
|
||||||
else:
|
else:
|
||||||
if PAsyncSocket(h).sendBuffer != "":
|
if PAsyncSocket(h).sendBuffer != "":
|
||||||
let sock = PAsyncSocket(h)
|
let sock = PAsyncSocket(h)
|
||||||
let bytesSent = sock.socket.sendAsync(sock.sendBuffer)
|
try:
|
||||||
assert bytesSent > 0
|
let bytesSent = sock.socket.sendAsync(sock.sendBuffer)
|
||||||
if bytesSent != sock.sendBuffer.len:
|
assert bytesSent > 0
|
||||||
sock.sendBuffer = sock.sendBuffer[bytesSent .. -1]
|
if bytesSent != sock.sendBuffer.len:
|
||||||
elif bytesSent == sock.sendBuffer.len:
|
sock.sendBuffer = sock.sendBuffer[bytesSent .. -1]
|
||||||
sock.sendBuffer = ""
|
elif bytesSent == sock.sendBuffer.len:
|
||||||
|
sock.sendBuffer = ""
|
||||||
|
|
||||||
if PAsyncSocket(h).handleWrite != nil:
|
if PAsyncSocket(h).handleWrite != nil:
|
||||||
PAsyncSocket(h).handleWrite(PAsyncSocket(h))
|
PAsyncSocket(h).handleWrite(PAsyncSocket(h))
|
||||||
|
except EOS:
|
||||||
|
# Most likely the socket closed before the full buffer could be sent to it.
|
||||||
|
sock.close() # TODO: Provide a handleError for users?
|
||||||
else:
|
else:
|
||||||
if PAsyncSocket(h).handleWrite != nil:
|
if PAsyncSocket(h).handleWrite != nil:
|
||||||
PAsyncSocket(h).handleWrite(PAsyncSocket(h))
|
PAsyncSocket(h).handleWrite(PAsyncSocket(h))
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
const
|
const
|
||||||
cb64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
|
cb64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
|
||||||
|
|
||||||
proc encode*(s: string, lineLen = 75, newLine="\13\10"): string =
|
template encodeInternal(s: expr, lineLen: int, newLine: string): stmt {.immediate.} =
|
||||||
## encodes `s` into base64 representation. After `lineLen` characters, a
|
## encodes `s` into base64 representation. After `lineLen` characters, a
|
||||||
## `newline` is added.
|
## `newline` is added.
|
||||||
var total = ((len(s) + 2) div 3) * 4
|
var total = ((len(s) + 2) div 3) * 4
|
||||||
|
|
@ -60,6 +60,16 @@ proc encode*(s: string, lineLen = 75, newLine="\13\10"): string =
|
||||||
else:
|
else:
|
||||||
assert(r == result.len)
|
assert(r == result.len)
|
||||||
|
|
||||||
|
proc encode*[T:TInteger|char](s: openarray[T], lineLen = 75, newLine="\13\10"): string =
|
||||||
|
## encodes `s` into base64 representation. After `lineLen` characters, a
|
||||||
|
## `newline` is added.
|
||||||
|
encodeInternal(s, lineLen, newLine)
|
||||||
|
|
||||||
|
proc encode*(s: string, lineLen = 75, newLine="\13\10"): string =
|
||||||
|
## encodes `s` into base64 representation. After `lineLen` characters, a
|
||||||
|
## `newline` is added.
|
||||||
|
encodeInternal(s, lineLen, newLine)
|
||||||
|
|
||||||
proc decodeByte(b: char): int {.inline.} =
|
proc decodeByte(b: char): int {.inline.} =
|
||||||
case b
|
case b
|
||||||
of '+': result = ord('>')
|
of '+': result = ord('>')
|
||||||
|
|
|
||||||
581
lib/pure/collections/LockFreeHash.nim
Normal file
581
lib/pure/collections/LockFreeHash.nim
Normal file
|
|
@ -0,0 +1,581 @@
|
||||||
|
#nimrod c -t:-march=i686 --cpu:amd64 --threads:on -d:release lockfreehash.nim
|
||||||
|
|
||||||
|
import baseutils, unsigned, math, hashes
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const
|
||||||
|
minTableSize = 8
|
||||||
|
reProbeLimit = 12
|
||||||
|
minCopyWork = 4096
|
||||||
|
intSize = sizeof(int)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
when sizeof(int) == 4: # 32bit
|
||||||
|
type
|
||||||
|
TRaw = range[0..1073741823]
|
||||||
|
## The range of uint values that can be stored directly in a value slot
|
||||||
|
## when on a 32 bit platform
|
||||||
|
|
||||||
|
elif sizeof(int) == 8: # 64bit
|
||||||
|
type
|
||||||
|
TRaw = range[0..4611686018427387903]
|
||||||
|
## The range of uint values that can be stored directly in a value slot
|
||||||
|
## when on a 64 bit platform
|
||||||
|
else: echo("unsupported platform")
|
||||||
|
|
||||||
|
type
|
||||||
|
TEntry = tuple
|
||||||
|
key: int
|
||||||
|
value: int
|
||||||
|
|
||||||
|
TEntryArr = ptr array[0..10_000_000, TEntry]
|
||||||
|
|
||||||
|
PConcTable[K,V] = ptr object {.pure.}
|
||||||
|
len: int
|
||||||
|
used: int
|
||||||
|
active: int
|
||||||
|
copyIdx: int
|
||||||
|
copyDone: int
|
||||||
|
next: PConcTable[K,V]
|
||||||
|
data: TEntryArr
|
||||||
|
|
||||||
|
|
||||||
|
proc setVal[K,V](table: var PConcTable[K,V], key: int, val: int,
|
||||||
|
expVal: int, match: bool): int
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Create a new table
|
||||||
|
proc newLFTable*[K,V](size: int = minTableSize): PConcTable[K,V] =
|
||||||
|
let
|
||||||
|
dataLen = max(nextPowerOfTwo(size), minTableSize)
|
||||||
|
dataSize = dataLen*sizeof(TEntry)
|
||||||
|
dataMem = allocShared0(dataSize)
|
||||||
|
tableSize = 7 * intSize
|
||||||
|
tableMem = allocShared0(tableSize)
|
||||||
|
table = cast[PConcTable[K,V]](tableMem)
|
||||||
|
table.len = dataLen
|
||||||
|
table.used = 0
|
||||||
|
table.active = 0
|
||||||
|
table.copyIdx = 0
|
||||||
|
table.copyDone = 0
|
||||||
|
table.next = nil
|
||||||
|
table.data = cast[TEntryArr](dataMem)
|
||||||
|
result = table
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Delete a table
|
||||||
|
proc deleteConcTable[K,V](tbl: PConcTable[K,V]) =
|
||||||
|
deallocShared(tbl.data)
|
||||||
|
deallocShared(tbl)
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
proc `[]`[K,V](table: var PConcTable[K,V], i: int): var TEntry {.inline.} =
|
||||||
|
table.data[i]
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
# State flags stored in ptr
|
||||||
|
|
||||||
|
|
||||||
|
proc pack[T](x: T): int {.inline.} =
|
||||||
|
result = (cast[int](x) shl 2)
|
||||||
|
#echo("packKey ",cast[int](x) , " -> ", result)
|
||||||
|
|
||||||
|
# Pop the flags off returning a 4 byte aligned ptr to our Key or Val
|
||||||
|
proc pop(x: int): int {.inline.} =
|
||||||
|
result = x and 0xFFFFFFFC'i32
|
||||||
|
|
||||||
|
# Pop the raw value off of our Key or Val
|
||||||
|
proc popRaw(x: int): int {.inline.} =
|
||||||
|
result = x shr 2
|
||||||
|
|
||||||
|
# Pop the flags off returning a 4 byte aligned ptr to our Key or Val
|
||||||
|
proc popPtr[V](x: int): ptr V {.inline.} =
|
||||||
|
result = cast[ptr V](pop(x))
|
||||||
|
#echo("popPtr " & $x & " -> " & $cast[int](result))
|
||||||
|
|
||||||
|
# Ghost (sentinel)
|
||||||
|
# K or V is no longer valid use new table
|
||||||
|
const Ghost = 0xFFFFFFFC
|
||||||
|
proc isGhost(x: int): bool {.inline.} =
|
||||||
|
result = x == 0xFFFFFFFC
|
||||||
|
|
||||||
|
# Tombstone
|
||||||
|
# applied to V = K is dead
|
||||||
|
proc isTomb(x: int): bool {.inline.} =
|
||||||
|
result = (x and 0x00000002) != 0
|
||||||
|
|
||||||
|
proc setTomb(x: int): int {.inline.} =
|
||||||
|
result = x or 0x00000002
|
||||||
|
|
||||||
|
# Prime
|
||||||
|
# K or V is in new table copied from old
|
||||||
|
proc isPrime(x: int): bool {.inline.} =
|
||||||
|
result = (x and 0x00000001) != 0
|
||||||
|
|
||||||
|
proc setPrime(x: int): int {.inline.} =
|
||||||
|
result = x or 0x00000001
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
##This is for i32 only need to override for i64
|
||||||
|
proc hashInt(x: int):int {.inline.} =
|
||||||
|
var h = uint32(x) #shr 2'u32
|
||||||
|
h = h xor (h shr 16'u32)
|
||||||
|
h *= 0x85ebca6b'u32
|
||||||
|
h = h xor (h shr 13'u32)
|
||||||
|
h *= 0xc2b2ae35'u32
|
||||||
|
h = h xor (h shr 16'u32)
|
||||||
|
result = int(h)
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
proc resize[K,V](self: PConcTable[K,V]): PConcTable[K,V] =
|
||||||
|
var next = atomic_load_n(self.next.addr, ATOMIC_RELAXED)
|
||||||
|
#echo("next = " & $cast[int](next))
|
||||||
|
if next != nil:
|
||||||
|
#echo("A new table already exists, copy in progress")
|
||||||
|
return next
|
||||||
|
var
|
||||||
|
oldLen = atomic_load_n(self.len.addr, ATOMIC_RELAXED)
|
||||||
|
newTable = newLFTable[K,V](oldLen*2)
|
||||||
|
success = atomic_compare_exchange_n(self.next.addr, next.addr, newTable,
|
||||||
|
false, ATOMIC_RELAXED, ATOMIC_RELAXED)
|
||||||
|
if not success:
|
||||||
|
echo("someone beat us to it! delete table we just created and return his " & $cast[int](next))
|
||||||
|
deleteConcTable(newTable)
|
||||||
|
return next
|
||||||
|
else:
|
||||||
|
echo("Created New Table! " & $cast[int](newTable) & " Size = " & $newTable.len)
|
||||||
|
return newTable
|
||||||
|
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
#proc keyEQ[K](key1: ptr K, key2: ptr K): bool {.inline.} =
|
||||||
|
proc keyEQ[K](key1: int, key2: int): bool {.inline.} =
|
||||||
|
result = false
|
||||||
|
when K is TRaw:
|
||||||
|
if key1 == key2:
|
||||||
|
result = true
|
||||||
|
else:
|
||||||
|
var
|
||||||
|
p1 = popPtr[K](key1)
|
||||||
|
p2 = popPtr[K](key2)
|
||||||
|
if p1 != nil and p2 != nil:
|
||||||
|
if cast[int](p1) == cast[int](p2):
|
||||||
|
return true
|
||||||
|
if p1[] == p2[]:
|
||||||
|
return true
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#proc tableFull(self: var PConcTable[K,V]) : bool {.inline.} =
|
||||||
|
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
proc copySlot[K,V](idx: int, oldTbl: var PConcTable[K,V], newTbl: var PConcTable[K,V]): bool =
|
||||||
|
#echo("Copy idx " & $idx)
|
||||||
|
var
|
||||||
|
oldVal = 0
|
||||||
|
oldkey = 0
|
||||||
|
ok = false
|
||||||
|
result = false
|
||||||
|
#Block the key so no other threads waste time here
|
||||||
|
while not ok:
|
||||||
|
ok = atomic_compare_exchange_n(oldTbl[idx].key.addr, oldKey.addr,
|
||||||
|
setTomb(oldKey), false, ATOMIC_RELAXED, ATOMIC_RELAXED)
|
||||||
|
#echo("oldKey was = " & $oldKey & " set it to tomb " & $setTomb(oldKey))
|
||||||
|
#Prevent new values from appearing in the old table by priming
|
||||||
|
oldVal = atomic_load_n(oldTbl[idx].value.addr, ATOMIC_RELAXED)
|
||||||
|
while not isPrime(oldVal):
|
||||||
|
var box = if oldVal == NULL or isTomb(oldVal) : oldVal.setTomb.setPrime
|
||||||
|
else: oldVal.setPrime
|
||||||
|
if atomic_compare_exchange_n(oldTbl[idx].value.addr, oldVal.addr,
|
||||||
|
box, false, ATOMIC_RELAXED, ATOMIC_RELAXED):
|
||||||
|
if isPrime(box) and isTomb(box):
|
||||||
|
return true
|
||||||
|
oldVal = box
|
||||||
|
break
|
||||||
|
#echo("oldVal was = ", oldVal, " set it to prime ", box)
|
||||||
|
if isPrime(oldVal) and isTomb(oldVal):
|
||||||
|
#when not (K is TRaw):
|
||||||
|
# deallocShared(popPtr[K](oldKey))
|
||||||
|
return false
|
||||||
|
if isTomb(oldVal):
|
||||||
|
echo("oldVal is Tomb!!!, should not happen")
|
||||||
|
if pop(oldVal) != NULL:
|
||||||
|
result = setVal(newTbl, pop(oldKey), pop(oldVal), NULL, true) == NULL
|
||||||
|
if result:
|
||||||
|
#echo("Copied a Slot! idx= " & $idx & " key= " & $oldKey & " val= " & $oldVal)
|
||||||
|
else:
|
||||||
|
#echo("copy slot failed")
|
||||||
|
# Our copy is done so we disable the old slot
|
||||||
|
while not ok:
|
||||||
|
ok = atomic_compare_exchange_n(oldTbl[idx].value.addr, oldVal.addr,
|
||||||
|
oldVal.setTomb.setPrime , false, ATOMIC_RELAXED, ATOMIC_RELAXED)
|
||||||
|
#echo("disabled old slot")
|
||||||
|
#echo"---------------------"
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
proc promote[K,V](table: var PConcTable[K,V]) =
|
||||||
|
var
|
||||||
|
newData = atomic_load_n(table.next.data.addr, ATOMIC_RELAXED)
|
||||||
|
newLen = atomic_load_n(table.next.len.addr, ATOMIC_RELAXED)
|
||||||
|
newUsed = atomic_load_n(table.next.used.addr, ATOMIC_RELAXED)
|
||||||
|
|
||||||
|
deallocShared(table.data)
|
||||||
|
atomic_store_n(table.data.addr, newData, ATOMIC_RELAXED)
|
||||||
|
atomic_store_n(table.len.addr, newLen, ATOMIC_RELAXED)
|
||||||
|
atomic_store_n(table.used.addr, newUsed, ATOMIC_RELAXED)
|
||||||
|
atomic_store_n(table.copyIdx.addr, 0, ATOMIC_RELAXED)
|
||||||
|
atomic_store_n(table.copyDone.addr, 0, ATOMIC_RELAXED)
|
||||||
|
deallocShared(table.next)
|
||||||
|
atomic_store_n(table.next.addr, nil, ATOMIC_RELAXED)
|
||||||
|
echo("new table swapped!")
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
proc checkAndPromote[K,V](table: var PConcTable[K,V], workDone: int): bool =
|
||||||
|
var
|
||||||
|
oldLen = atomic_load_n(table.len.addr, ATOMIC_RELAXED)
|
||||||
|
copyDone = atomic_load_n(table.copyDone.addr, ATOMIC_RELAXED)
|
||||||
|
ok: bool
|
||||||
|
result = false
|
||||||
|
if workDone > 0:
|
||||||
|
#echo("len to copy =" & $oldLen)
|
||||||
|
#echo("copyDone + workDone = " & $copyDone & " + " & $workDone)
|
||||||
|
while not ok:
|
||||||
|
ok = atomic_compare_exchange_n(table.copyDone.addr, copyDone.addr,
|
||||||
|
copyDone + workDone, false, ATOMIC_RELAXED, ATOMIC_RELAXED)
|
||||||
|
#if ok: echo("set copyDone")
|
||||||
|
# If the copy is done we can promote this table
|
||||||
|
if copyDone + workDone >= oldLen:
|
||||||
|
# Swap new data
|
||||||
|
#echo("work is done!")
|
||||||
|
table.promote
|
||||||
|
result = true
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
proc copySlotAndCheck[K,V](table: var PConcTable[K,V], idx: int):
|
||||||
|
PConcTable[K,V] =
|
||||||
|
var
|
||||||
|
newTable = cast[PConcTable[K,V]](atomic_load_n(table.next.addr, ATOMIC_RELAXED))
|
||||||
|
result = newTable
|
||||||
|
if newTable != nil and copySlot(idx, table, newTable):
|
||||||
|
#echo("copied a single slot, idx = " & $idx)
|
||||||
|
if checkAndPromote(table, 1): return table
|
||||||
|
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
proc helpCopy[K,V](table: var PConcTable[K,V]): PConcTable[K,V] =
|
||||||
|
var
|
||||||
|
newTable = cast[PConcTable[K,V]](atomic_load_n(table.next.addr, ATOMIC_RELAXED))
|
||||||
|
result = newTable
|
||||||
|
if newTable != nil:
|
||||||
|
var
|
||||||
|
oldLen = atomic_load_n(table.len.addr, ATOMIC_RELAXED)
|
||||||
|
copyDone = atomic_load_n(table.copyDone.addr, ATOMIC_RELAXED)
|
||||||
|
copyIdx = 0
|
||||||
|
work = min(oldLen, minCopyWork)
|
||||||
|
#panicStart = -1
|
||||||
|
workDone = 0
|
||||||
|
if copyDone < oldLen:
|
||||||
|
var ok: bool
|
||||||
|
while not ok:
|
||||||
|
ok = atomic_compare_exchange_n(table.copyIdx.addr, copyIdx.addr,
|
||||||
|
copyIdx + work, false, ATOMIC_RELAXED, ATOMIC_RELAXED)
|
||||||
|
#echo("copy idx = ", copyIdx)
|
||||||
|
for i in 0..work-1:
|
||||||
|
var idx = (copyIdx + i) and (oldLen - 1)
|
||||||
|
if copySlot(idx, table, newTable):
|
||||||
|
workDone += 1
|
||||||
|
if workDone > 0:
|
||||||
|
#echo("did work ", workDone, " on thread ", cast[int](myThreadID[pointer]()))
|
||||||
|
if checkAndPromote(table, workDone): return table
|
||||||
|
# In case a thread finished all the work then got stalled before promotion
|
||||||
|
if checkAndPromote(table, 0): return table
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
proc setVal[K,V](table: var PConcTable[K,V], key: int, val: int,
|
||||||
|
expVal: int, match: bool): int =
|
||||||
|
#echo("-try set- in table ", " key = ", (popPtr[K](key)[]), " val = ", val)
|
||||||
|
when K is TRaw:
|
||||||
|
var idx = hashInt(key)
|
||||||
|
else:
|
||||||
|
var idx = popPtr[K](key)[].hash
|
||||||
|
var
|
||||||
|
nextTable: PConcTable[K,V]
|
||||||
|
probes = 1
|
||||||
|
# spin until we find a key slot or build and jump to next table
|
||||||
|
while true:
|
||||||
|
idx = idx and (table.len - 1)
|
||||||
|
#echo("try set idx = " & $idx & "for" & $key)
|
||||||
|
var
|
||||||
|
probedKey = NULL
|
||||||
|
openKey = atomic_compare_exchange_n(table[idx].key.addr, probedKey.addr,
|
||||||
|
key, false, ATOMIC_RELAXED, ATOMIC_RELAXED)
|
||||||
|
if openKey:
|
||||||
|
if val.isTomb:
|
||||||
|
#echo("val was tomb, bail, no reason to set an open slot to tomb")
|
||||||
|
return val
|
||||||
|
#increment used slots
|
||||||
|
#echo("found an open slot, total used = " &
|
||||||
|
#$atomic_add_fetch(table.used.addr, 1, ATOMIC_RELAXED))
|
||||||
|
discard atomic_add_fetch(table.used.addr, 1, ATOMIC_RELAXED)
|
||||||
|
break # We found an open slot
|
||||||
|
#echo("set idx ", idx, " key = ", key, " probed = ", probedKey)
|
||||||
|
if keyEQ[K](probedKey, key):
|
||||||
|
#echo("we found the matching slot")
|
||||||
|
break # We found a matching slot
|
||||||
|
if (not(expVal != NULL and match)) and (probes >= reProbeLimit or key.isTomb):
|
||||||
|
if key.isTomb: echo("Key is Tombstone")
|
||||||
|
#if probes >= reProbeLimit: echo("Too much probing " & $probes)
|
||||||
|
#echo("try to resize")
|
||||||
|
#create next bigger table
|
||||||
|
nextTable = resize(table)
|
||||||
|
#help do some copying
|
||||||
|
#echo("help copy old table to new")
|
||||||
|
nextTable = helpCopy(table)
|
||||||
|
#now setVal in the new table instead
|
||||||
|
#echo("jumping to next table to set val")
|
||||||
|
return setVal(nextTable, key, val, expVal, match)
|
||||||
|
else:
|
||||||
|
idx += 1
|
||||||
|
probes += 1
|
||||||
|
# Done spinning for a new slot
|
||||||
|
var oldVal = atomic_load_n(table[idx].value.addr, ATOMIC_RELAXED)
|
||||||
|
if val == oldVal:
|
||||||
|
#echo("this val is alredy in the slot")
|
||||||
|
return oldVal
|
||||||
|
nextTable = atomic_load_n(table.next.addr, ATOMIC_SEQ_CST)
|
||||||
|
if nextTable == nil and
|
||||||
|
((oldVal == NULL and
|
||||||
|
(probes >= reProbeLimit or table.used / table.len > 0.8)) or
|
||||||
|
(isPrime(oldVal))):
|
||||||
|
if table.used / table.len > 0.8: echo("resize because usage ratio = " &
|
||||||
|
$(table.used / table.len))
|
||||||
|
if isPrime(oldVal): echo("old val isPrime, should be a rare mem ordering event")
|
||||||
|
nextTable = resize(table)
|
||||||
|
if nextTable != nil:
|
||||||
|
#echo("tomb old slot then set in new table")
|
||||||
|
nextTable = copySlotAndCheck(table,idx)
|
||||||
|
return setVal(nextTable, key, val, expVal, match)
|
||||||
|
# Finaly ready to add new val to table
|
||||||
|
while true:
|
||||||
|
if match and oldVal != expVal:
|
||||||
|
#echo("set failed, no match oldVal= " & $oldVal & " expVal= " & $expVal)
|
||||||
|
return oldVal
|
||||||
|
if atomic_compare_exchange_n(table[idx].value.addr, oldVal.addr,
|
||||||
|
val, false, ATOMIC_RELEASE, ATOMIC_RELAXED):
|
||||||
|
#echo("val set at table " & $cast[int](table))
|
||||||
|
if expVal != NULL:
|
||||||
|
if (oldVal == NULL or isTomb(oldVal)) and not isTomb(val):
|
||||||
|
discard atomic_add_fetch(table.active.addr, 1, ATOMIC_RELAXED)
|
||||||
|
elif not (oldVal == NULL or isTomb(oldVal)) and isTomb(val):
|
||||||
|
discard atomic_add_fetch(table.active.addr, -1, ATOMIC_RELAXED)
|
||||||
|
if oldVal == NULL and expVal != NULL:
|
||||||
|
return setTomb(oldVal)
|
||||||
|
else: return oldVal
|
||||||
|
if isPrime(oldVal):
|
||||||
|
nextTable = copySlotAndCheck(table, idx)
|
||||||
|
return setVal(nextTable, key, val, expVal, match)
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
proc getVal[K,V](table: var PConcTable[K,V], key: int): int =
|
||||||
|
#echo("-try get- key = " & $key)
|
||||||
|
when K is TRaw:
|
||||||
|
var idx = hashInt(key)
|
||||||
|
else:
|
||||||
|
var idx = popPtr[K](key)[].hash
|
||||||
|
#echo("get idx ", idx)
|
||||||
|
var
|
||||||
|
probes = 0
|
||||||
|
val: int
|
||||||
|
while true:
|
||||||
|
idx = idx and (table.len - 1)
|
||||||
|
var
|
||||||
|
newTable: PConcTable[K,V] # = atomic_load_n(table.next.addr, ATOMIC_ACQUIRE)
|
||||||
|
probedKey = atomic_load_n(table[idx].key.addr, ATOMIC_SEQ_CST)
|
||||||
|
if keyEQ[K](probedKey, key):
|
||||||
|
#echo("found key after ", probes+1)
|
||||||
|
val = atomic_load_n(table[idx].value.addr, ATOMIC_ACQUIRE)
|
||||||
|
if not isPrime(val):
|
||||||
|
if isTomb(val):
|
||||||
|
#echo("val was tomb but not prime")
|
||||||
|
return NULL
|
||||||
|
else:
|
||||||
|
#echo("-GotIt- idx = ", idx, " key = ", key, " val ", val )
|
||||||
|
return val
|
||||||
|
else:
|
||||||
|
newTable = copySlotAndCheck(table, idx)
|
||||||
|
return getVal(newTable, key)
|
||||||
|
else:
|
||||||
|
#echo("probe ", probes, " idx = ", idx, " key = ", key, " found ", probedKey )
|
||||||
|
if probes >= reProbeLimit*4 or key.isTomb:
|
||||||
|
if newTable == nil:
|
||||||
|
#echo("too many probes and no new table ", key, " ", idx )
|
||||||
|
return NULL
|
||||||
|
else:
|
||||||
|
newTable = helpCopy(table)
|
||||||
|
return getVal(newTable, key)
|
||||||
|
idx += 1
|
||||||
|
probes += 1
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#proc set*(table: var PConcTable[TRaw,TRaw], key: TRaw, val: TRaw) =
|
||||||
|
# discard setVal(table, pack(key), pack(key), NULL, false)
|
||||||
|
|
||||||
|
#proc set*[V](table: var PConcTable[TRaw,V], key: TRaw, val: ptr V) =
|
||||||
|
# discard setVal(table, pack(key), cast[int](val), NULL, false)
|
||||||
|
|
||||||
|
proc set*[K,V](table: var PConcTable[K,V], key: var K, val: var V) =
|
||||||
|
when not (K is TRaw):
|
||||||
|
var newKey = cast[int](copyShared(key))
|
||||||
|
else:
|
||||||
|
var newKey = pack(key)
|
||||||
|
when not (V is TRaw):
|
||||||
|
var newVal = cast[int](copyShared(val))
|
||||||
|
else:
|
||||||
|
var newVal = pack(val)
|
||||||
|
var oldPtr = pop(setVal(table, newKey, newVal, NULL, false))
|
||||||
|
#echo("oldPtr = ", cast[int](oldPtr), " newPtr = ", cast[int](newPtr))
|
||||||
|
when not (V is TRaw):
|
||||||
|
if newVal != oldPtr and oldPtr != NULL:
|
||||||
|
deallocShared(cast[ptr V](oldPtr))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
proc get*[K,V](table: var PConcTable[K,V], key: var K): V =
|
||||||
|
when not (V is TRaw):
|
||||||
|
when not (K is TRaw):
|
||||||
|
return popPtr[V](getVal(table, cast[int](key.addr)))[]
|
||||||
|
else:
|
||||||
|
return popPtr[V](getVal(table, pack(key)))[]
|
||||||
|
else:
|
||||||
|
when not (K is TRaw):
|
||||||
|
return popRaw(getVal(table, cast[int](key.addr)))
|
||||||
|
else:
|
||||||
|
return popRaw(getVal(table, pack(key)))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#proc `[]`[K,V](table: var PConcTable[K,V], key: K): PEntry[K,V] {.inline.} =
|
||||||
|
# getVal(table, key)
|
||||||
|
|
||||||
|
#proc `[]=`[K,V](table: var PConcTable[K,V], key: K, val: V): PEntry[K,V] {.inline.} =
|
||||||
|
# setVal(table, key, val)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#Tests ----------------------------
|
||||||
|
when isMainModule:
|
||||||
|
import locks, times, mersenne
|
||||||
|
|
||||||
|
const
|
||||||
|
numTests = 100000
|
||||||
|
numThreads = 10
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
type
|
||||||
|
TTestObj = tuple
|
||||||
|
thr: int
|
||||||
|
f0: int
|
||||||
|
f1: int
|
||||||
|
|
||||||
|
TData = tuple[k: string,v: TTestObj]
|
||||||
|
PDataArr = array[0..numTests-1, TData]
|
||||||
|
Dict = PConcTable[string,TTestObj]
|
||||||
|
|
||||||
|
var
|
||||||
|
thr: array[0..numThreads-1, TThread[Dict]]
|
||||||
|
|
||||||
|
table = newLFTable[string,TTestObj](8)
|
||||||
|
rand = newMersenneTwister(2525)
|
||||||
|
|
||||||
|
proc createSampleData(len: int): PDataArr =
|
||||||
|
#result = cast[PDataArr](allocShared0(sizeof(TData)*numTests))
|
||||||
|
for i in 0..len-1:
|
||||||
|
result[i].k = "mark" & $(i+1)
|
||||||
|
#echo("mark" & $(i+1), " ", hash("mark" & $(i+1)))
|
||||||
|
result[i].v.thr = 0
|
||||||
|
result[i].v.f0 = i+1
|
||||||
|
result[i].v.f1 = 0
|
||||||
|
#echo("key = " & $(i+1) & " Val ptr = " & $cast[int](result[i].v.addr))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
proc threadProc(tp: Dict) {.thread.} =
|
||||||
|
var t = cpuTime();
|
||||||
|
for i in 1..numTests:
|
||||||
|
var key = "mark" & $(i)
|
||||||
|
var got = table.get(key)
|
||||||
|
got.thr = cast[int](myThreadID[pointer]())
|
||||||
|
got.f1 = got.f1 + 1
|
||||||
|
table.set(key, got)
|
||||||
|
t = cpuTime() - t
|
||||||
|
echo t
|
||||||
|
|
||||||
|
|
||||||
|
var testData = createSampleData(numTests)
|
||||||
|
|
||||||
|
for i in 0..numTests-1:
|
||||||
|
table.set(testData[i].k, testData[i].v)
|
||||||
|
|
||||||
|
var i = 0
|
||||||
|
while i < numThreads:
|
||||||
|
createThread(thr[i], threadProc, table)
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
joinThreads(thr)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var fails = 0
|
||||||
|
|
||||||
|
for i in 0..numTests-1:
|
||||||
|
var got = table.get(testData[i].k)
|
||||||
|
if got.f0 != i+1 or got.f1 != numThreads:
|
||||||
|
fails += 1
|
||||||
|
echo(got)
|
||||||
|
|
||||||
|
echo("Failed read or write = ", fails)
|
||||||
|
|
||||||
|
|
||||||
|
#for i in 1..numTests:
|
||||||
|
# echo(i, " = ", hashInt(i) and 8191)
|
||||||
|
|
||||||
|
deleteConcTable(table)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
41
lib/pure/collections/baseutils.nim
Normal file
41
lib/pure/collections/baseutils.nim
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
## Useful Constants
|
||||||
|
const NULL* = 0
|
||||||
|
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
## Memory Utility Functions
|
||||||
|
|
||||||
|
proc newHeap*[T](): ptr T =
|
||||||
|
result = cast[ptr T](alloc0(sizeof(T)))
|
||||||
|
|
||||||
|
proc copyNew*[T](x: var T): ptr T =
|
||||||
|
var
|
||||||
|
size = sizeof(T)
|
||||||
|
mem = alloc(size)
|
||||||
|
copyMem(mem, x.addr, size)
|
||||||
|
return cast[ptr T](mem)
|
||||||
|
|
||||||
|
proc copyTo*[T](val: var T, dest: int) =
|
||||||
|
copyMem(pointer(dest), val.addr, sizeof(T))
|
||||||
|
|
||||||
|
proc allocType*[T](): pointer = alloc(sizeof(T))
|
||||||
|
|
||||||
|
proc newShared*[T](): ptr T =
|
||||||
|
result = cast[ptr T](allocShared0(sizeof(T)))
|
||||||
|
|
||||||
|
proc copyShared*[T](x: var T): ptr T =
|
||||||
|
var
|
||||||
|
size = sizeof(T)
|
||||||
|
mem = allocShared(size)
|
||||||
|
copyMem(mem, x.addr, size)
|
||||||
|
return cast[ptr T](mem)
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
## Pointer arithmetic
|
||||||
|
|
||||||
|
proc `+`*(p: pointer, i: int): pointer {.inline.} =
|
||||||
|
cast[pointer](cast[int](p) + i)
|
||||||
|
|
@ -117,6 +117,57 @@ proc filter*[T](seq1: seq[T], pred: proc(item: T): bool {.closure.}): seq[T] =
|
||||||
## assert f2 == @["yellow"]
|
## assert f2 == @["yellow"]
|
||||||
accumulateResult(filter(seq1, pred))
|
accumulateResult(filter(seq1, pred))
|
||||||
|
|
||||||
|
proc delete*[T](s: var seq[T], first=0, last=0) =
|
||||||
|
## Deletes in `s` the items at position `first` .. `last`. This modifies
|
||||||
|
## `s` itself, it does not return a copy.
|
||||||
|
##
|
||||||
|
## Example:
|
||||||
|
##
|
||||||
|
##.. code-block:: nimrod
|
||||||
|
## let outcome = @[1,1,1,1,1,1,1,1]
|
||||||
|
## var dest = @[1,1,1,2,2,2,2,2,2,1,1,1,1,1]
|
||||||
|
## dest.delete(3, 8)
|
||||||
|
## assert outcome == dest
|
||||||
|
|
||||||
|
var i = first
|
||||||
|
var j = last+1
|
||||||
|
var newLen = len(s)-j+i
|
||||||
|
while i < newLen:
|
||||||
|
s[i].shallowCopy(s[j])
|
||||||
|
inc(i)
|
||||||
|
inc(j)
|
||||||
|
setlen(s, newLen)
|
||||||
|
|
||||||
|
proc insert*[T](dest: var seq[T], src: openArray[T], pos=0) =
|
||||||
|
## Inserts items from `src` into `dest` at position `pos`. This modifies
|
||||||
|
## `dest` itself, it does not return a copy.
|
||||||
|
##
|
||||||
|
## Example:
|
||||||
|
##
|
||||||
|
##.. code-block:: nimrod
|
||||||
|
## var dest = @[1,1,1,1,1,1,1,1]
|
||||||
|
## let
|
||||||
|
## src = @[2,2,2,2,2,2]
|
||||||
|
## outcome = @[1,1,1,2,2,2,2,2,2,1,1,1,1,1]
|
||||||
|
## dest.insert(src, 3)
|
||||||
|
## assert dest == outcome
|
||||||
|
|
||||||
|
var j = len(dest) - 1
|
||||||
|
var i = len(dest) + len(src) - 1
|
||||||
|
dest.setLen(i + 1)
|
||||||
|
|
||||||
|
# Move items after `pos` to the end of the sequence.
|
||||||
|
while j >= pos:
|
||||||
|
dest[i].shallowCopy(dest[j])
|
||||||
|
dec(i)
|
||||||
|
dec(j)
|
||||||
|
# Insert items from `dest` into `dest` at `pos`
|
||||||
|
inc(j)
|
||||||
|
for item in src:
|
||||||
|
dest[j] = item
|
||||||
|
inc(j)
|
||||||
|
|
||||||
|
|
||||||
template filterIt*(seq1, pred: expr): expr {.immediate.} =
|
template filterIt*(seq1, pred: expr): expr {.immediate.} =
|
||||||
## Returns a new sequence with all the items that fulfilled the predicate.
|
## Returns a new sequence with all the items that fulfilled the predicate.
|
||||||
##
|
##
|
||||||
|
|
@ -312,4 +363,22 @@ when isMainModule:
|
||||||
assert multiplication == 495, "Multiplication is (5*(9*(11)))"
|
assert multiplication == 495, "Multiplication is (5*(9*(11)))"
|
||||||
assert concatenation == "nimrodiscool"
|
assert concatenation == "nimrodiscool"
|
||||||
|
|
||||||
|
block: # delete tests
|
||||||
|
let outcome = @[1,1,1,1,1,1,1,1]
|
||||||
|
var dest = @[1,1,1,2,2,2,2,2,2,1,1,1,1,1]
|
||||||
|
dest.delete(3, 8)
|
||||||
|
assert outcome == dest, """\
|
||||||
|
Deleting range 3-9 from [1,1,1,2,2,2,2,2,2,1,1,1,1,1]
|
||||||
|
is [1,1,1,1,1,1,1,1]"""
|
||||||
|
|
||||||
|
block: # insert tests
|
||||||
|
var dest = @[1,1,1,1,1,1,1,1]
|
||||||
|
let
|
||||||
|
src = @[2,2,2,2,2,2]
|
||||||
|
outcome = @[1,1,1,2,2,2,2,2,2,1,1,1,1,1]
|
||||||
|
dest.insert(src, 3)
|
||||||
|
assert dest == outcome, """\
|
||||||
|
Inserting [2,2,2,2,2,2] into [1,1,1,1,1,1,1,1]
|
||||||
|
at 3 is [1,1,1,2,2,2,2,2,2,1,1,1,1,1]"""
|
||||||
|
|
||||||
echo "Finished doc tests"
|
echo "Finished doc tests"
|
||||||
|
|
|
||||||
|
|
@ -64,10 +64,10 @@ const
|
||||||
proc newMonitor*(): PFSMonitor =
|
proc newMonitor*(): PFSMonitor =
|
||||||
## Creates a new file system monitor.
|
## Creates a new file system monitor.
|
||||||
new(result)
|
new(result)
|
||||||
result.fd = inotifyInit()
|
|
||||||
result.targets = initTable[cint, string]()
|
result.targets = initTable[cint, string]()
|
||||||
|
result.fd = inotifyInit()
|
||||||
if result.fd < 0:
|
if result.fd < 0:
|
||||||
OSError()
|
OSError(OSLastError())
|
||||||
|
|
||||||
proc add*(monitor: PFSMonitor, target: string,
|
proc add*(monitor: PFSMonitor, target: string,
|
||||||
filters = {MonitorAll}): cint {.discardable.} =
|
filters = {MonitorAll}): cint {.discardable.} =
|
||||||
|
|
@ -93,7 +93,7 @@ proc add*(monitor: PFSMonitor, target: string,
|
||||||
|
|
||||||
result = inotifyAddWatch(monitor.fd, target, INFilter.uint32)
|
result = inotifyAddWatch(monitor.fd, target, INFilter.uint32)
|
||||||
if result < 0:
|
if result < 0:
|
||||||
OSError()
|
OSError(OSLastError())
|
||||||
monitor.targets.add(result, target)
|
monitor.targets.add(result, target)
|
||||||
|
|
||||||
proc del*(monitor: PFSMonitor, wd: cint) =
|
proc del*(monitor: PFSMonitor, wd: cint) =
|
||||||
|
|
@ -101,7 +101,7 @@ proc del*(monitor: PFSMonitor, wd: cint) =
|
||||||
##
|
##
|
||||||
## If ``wd`` is not a part of ``monitor`` an EOS error is raised.
|
## If ``wd`` is not a part of ``monitor`` an EOS error is raised.
|
||||||
if inotifyRmWatch(monitor.fd, wd) < 0:
|
if inotifyRmWatch(monitor.fd, wd) < 0:
|
||||||
OSError()
|
OSError(OSLastError())
|
||||||
|
|
||||||
proc getEvent(m: PFSMonitor, fd: cint): seq[TMonitorEvent] =
|
proc getEvent(m: PFSMonitor, fd: cint): seq[TMonitorEvent] =
|
||||||
result = @[]
|
result = @[]
|
||||||
|
|
@ -184,7 +184,7 @@ proc FSMonitorRead(h: PObject) =
|
||||||
proc toDelegate(m: PFSMonitor): PDelegate =
|
proc toDelegate(m: PFSMonitor): PDelegate =
|
||||||
result = newDelegate()
|
result = newDelegate()
|
||||||
result.deleVal = m
|
result.deleVal = m
|
||||||
result.fd = m.fd
|
result.fd = (type(result.fd))(m.fd)
|
||||||
result.mode = fmRead
|
result.mode = fmRead
|
||||||
result.handleRead = FSMonitorRead
|
result.handleRead = FSMonitorRead
|
||||||
result.open = true
|
result.open = true
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,8 @@ proc expectReply(ftp: PFTPClient): TaintedString =
|
||||||
proc send*(ftp: PFTPClient, m: string): TaintedString =
|
proc send*(ftp: PFTPClient, m: string): TaintedString =
|
||||||
## Send a message to the server, and wait for a primary reply.
|
## Send a message to the server, and wait for a primary reply.
|
||||||
## ``\c\L`` is added for you.
|
## ``\c\L`` is added for you.
|
||||||
ftp.getCSock().send(m & "\c\L")
|
blockingOperation(ftp.getCSock()):
|
||||||
|
ftp.getCSock().send(m & "\c\L")
|
||||||
return ftp.expectReply()
|
return ftp.expectReply()
|
||||||
|
|
||||||
proc assertReply(received: TaintedString, expected: string) =
|
proc assertReply(received: TaintedString, expected: string) =
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,37 @@
|
||||||
##
|
##
|
||||||
## echo loadHtml("mydirty.html")
|
## echo loadHtml("mydirty.html")
|
||||||
##
|
##
|
||||||
##
|
|
||||||
## Every tag in the resulting tree is in lower case.
|
## Every tag in the resulting tree is in lower case.
|
||||||
##
|
##
|
||||||
## **Note:** The resulting ``PXmlNode`` already uses the ``clientData`` field,
|
## **Note:** The resulting ``PXmlNode`` already uses the ``clientData`` field,
|
||||||
## so it cannot be used by clients of this library.
|
## so it cannot be used by clients of this library.
|
||||||
|
##
|
||||||
|
## Example: Transforming hyperlinks
|
||||||
|
## ================================
|
||||||
|
##
|
||||||
|
## This code demonstrates how you can iterate over all the tags in an HTML file
|
||||||
|
## and write back the modified version. In this case we look for hyperlinks
|
||||||
|
## ending with the extension ``.rst`` and convert them to ``.html``.
|
||||||
|
##
|
||||||
|
## .. code-block:: nimrod
|
||||||
|
##
|
||||||
|
## import htmlparser
|
||||||
|
## import xmltree # To use '$' for PXmlNode
|
||||||
|
## import strtabs # To access PXmlAttributes
|
||||||
|
## import os # To use splitFile
|
||||||
|
## import strutils # To use cmpIgnoreCase
|
||||||
|
##
|
||||||
|
## proc transformHyperlinks() =
|
||||||
|
## let html = loadHTML("input.html")
|
||||||
|
##
|
||||||
|
## for a in html.findAll("a"):
|
||||||
|
## let href = a.attrs["href"]
|
||||||
|
## if not href.isNil:
|
||||||
|
## let (dir, filename, ext) = splitFile(href)
|
||||||
|
## if cmpIgnoreCase(ext, ".rst") == 0:
|
||||||
|
## a.attrs["href"] = dir / filename & ".html"
|
||||||
|
##
|
||||||
|
## writeFile("output.html", $html)
|
||||||
|
|
||||||
import strutils, streams, parsexml, xmltree, unicode, strtabs
|
import strutils, streams, parsexml, xmltree, unicode, strtabs
|
||||||
|
|
||||||
|
|
@ -528,7 +554,7 @@ proc parseHtml*(s: PStream, filename: string,
|
||||||
## parses the XML from stream `s` and returns a ``PXmlNode``. Every
|
## parses the XML from stream `s` and returns a ``PXmlNode``. Every
|
||||||
## occured parsing error is added to the `errors` sequence.
|
## occured parsing error is added to the `errors` sequence.
|
||||||
var x: TXmlParser
|
var x: TXmlParser
|
||||||
open(x, s, filename, {reportComments})
|
open(x, s, filename, {reportComments, reportWhitespace})
|
||||||
next(x)
|
next(x)
|
||||||
# skip the DOCTYPE:
|
# skip the DOCTYPE:
|
||||||
if x.kind == xmlSpecial: next(x)
|
if x.kind == xmlSpecial: next(x)
|
||||||
|
|
|
||||||
|
|
@ -224,11 +224,13 @@ type
|
||||||
TAsyncHTTPServer = object of TServer
|
TAsyncHTTPServer = object of TServer
|
||||||
asyncSocket: PAsyncSocket
|
asyncSocket: PAsyncSocket
|
||||||
|
|
||||||
proc open*(s: var TServer, port = TPort(80)) =
|
proc open*(s: var TServer, port = TPort(80), reuseAddr = false) =
|
||||||
## creates a new server at port `port`. If ``port == 0`` a free port is
|
## creates a new server at port `port`. If ``port == 0`` a free port is
|
||||||
## acquired that can be accessed later by the ``port`` proc.
|
## acquired that can be accessed later by the ``port`` proc.
|
||||||
s.socket = socket(AF_INET)
|
s.socket = socket(AF_INET)
|
||||||
if s.socket == InvalidSocket: OSError(OSLastError())
|
if s.socket == InvalidSocket: OSError(OSLastError())
|
||||||
|
if reuseAddr:
|
||||||
|
s.socket.setSockOpt(OptReuseAddr, True)
|
||||||
bindAddr(s.socket, port)
|
bindAddr(s.socket, port)
|
||||||
listen(s.socket)
|
listen(s.socket)
|
||||||
|
|
||||||
|
|
@ -399,8 +401,9 @@ proc nextAsync(s: PAsyncHTTPServer) =
|
||||||
var value = ""
|
var value = ""
|
||||||
i = header.parseUntil(key, ':')
|
i = header.parseUntil(key, ':')
|
||||||
inc(i) # skip :
|
inc(i) # skip :
|
||||||
i += header.skipWhiteSpace(i)
|
if i < header.len:
|
||||||
i += header.parseUntil(value, {'\c', '\L'}, i)
|
i += header.skipWhiteSpace(i)
|
||||||
|
i += header.parseUntil(value, {'\c', '\L'}, i)
|
||||||
s.headers[key] = value
|
s.headers[key] = value
|
||||||
else:
|
else:
|
||||||
s.client.close()
|
s.client.close()
|
||||||
|
|
@ -475,7 +478,8 @@ proc nextAsync(s: PAsyncHTTPServer) =
|
||||||
|
|
||||||
proc asyncHTTPServer*(handleRequest: proc (server: PAsyncHTTPServer, client: TSocket,
|
proc asyncHTTPServer*(handleRequest: proc (server: PAsyncHTTPServer, client: TSocket,
|
||||||
path, query: string): bool {.closure.},
|
path, query: string): bool {.closure.},
|
||||||
port = TPort(80), address = ""): PAsyncHTTPServer =
|
port = TPort(80), address = "",
|
||||||
|
reuseAddr = false): PAsyncHTTPServer =
|
||||||
## Creates an Asynchronous HTTP server at ``port``.
|
## Creates an Asynchronous HTTP server at ``port``.
|
||||||
var capturedRet: PAsyncHTTPServer
|
var capturedRet: PAsyncHTTPServer
|
||||||
new(capturedRet)
|
new(capturedRet)
|
||||||
|
|
@ -486,6 +490,8 @@ proc asyncHTTPServer*(handleRequest: proc (server: PAsyncHTTPServer, client: TSo
|
||||||
let quit = handleRequest(capturedRet, capturedRet.client, capturedRet.path,
|
let quit = handleRequest(capturedRet, capturedRet.client, capturedRet.path,
|
||||||
capturedRet.query)
|
capturedRet.query)
|
||||||
if quit: capturedRet.asyncSocket.close()
|
if quit: capturedRet.asyncSocket.close()
|
||||||
|
if reuseAddr:
|
||||||
|
capturedRet.asyncSocket.setSockOpt(OptReuseAddr, True)
|
||||||
|
|
||||||
capturedRet.asyncSocket.bindAddr(port, address)
|
capturedRet.asyncSocket.bindAddr(port, address)
|
||||||
capturedRet.asyncSocket.listen()
|
capturedRet.asyncSocket.listen()
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,7 @@ type
|
||||||
params*: seq[string] ## Parameters of the IRC message
|
params*: seq[string] ## Parameters of the IRC message
|
||||||
origin*: string ## The channel/user that this msg originated from
|
origin*: string ## The channel/user that this msg originated from
|
||||||
raw*: string ## Raw IRC message
|
raw*: string ## Raw IRC message
|
||||||
|
timestamp*: TTime ## UNIX epoch time the message was received
|
||||||
|
|
||||||
proc send*(irc: PIRC, message: string, sendImmediately = false) =
|
proc send*(irc: PIRC, message: string, sendImmediately = false) =
|
||||||
## Sends ``message`` as a raw command. It adds ``\c\L`` for you.
|
## Sends ``message`` as a raw command. It adds ``\c\L`` for you.
|
||||||
|
|
@ -160,9 +161,10 @@ proc isNumber(s: string): bool =
|
||||||
result = i == s.len and s.len > 0
|
result = i == s.len and s.len > 0
|
||||||
|
|
||||||
proc parseMessage(msg: string): TIRCEvent =
|
proc parseMessage(msg: string): TIRCEvent =
|
||||||
result.typ = EvMsg
|
result.typ = EvMsg
|
||||||
result.cmd = MUnknown
|
result.cmd = MUnknown
|
||||||
result.raw = msg
|
result.raw = msg
|
||||||
|
result.timestamp = times.getTime()
|
||||||
var i = 0
|
var i = 0
|
||||||
# Process the prefix
|
# Process the prefix
|
||||||
if msg[i] == ':':
|
if msg[i] == ':':
|
||||||
|
|
|
||||||
39
lib/pure/mersenne.nim
Normal file
39
lib/pure/mersenne.nim
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
import unsigned
|
||||||
|
|
||||||
|
type
|
||||||
|
TMersenneTwister* = object
|
||||||
|
mt: array[0..623, uint32]
|
||||||
|
index: int
|
||||||
|
|
||||||
|
proc newMersenneTwister*(seed: int): TMersenneTwister =
|
||||||
|
result.index = 0
|
||||||
|
result.mt[0]= uint32(seed)
|
||||||
|
for i in 1..623'u32:
|
||||||
|
result.mt[i]= (0x6c078965'u32 * (result.mt[i-1] xor (result.mt[i-1] shr 30'u32)) + i)
|
||||||
|
|
||||||
|
proc generateNumbers(m: var TMersenneTwister) =
|
||||||
|
for i in 0..623:
|
||||||
|
var y = (m.mt[i] and 0x80000000'u32) + (m.mt[(i+1) mod 624] and 0x7fffffff'u32)
|
||||||
|
m.mt[i] = m.mt[(i+397) mod 624] xor uint32(y shr 1'u32)
|
||||||
|
if (y mod 2'u32) != 0:
|
||||||
|
m.mt[i] = m.mt[i] xor 0x9908b0df'u32
|
||||||
|
|
||||||
|
proc getNum*(m: var TMersenneTwister): int =
|
||||||
|
if m.index == 0:
|
||||||
|
generateNumbers(m)
|
||||||
|
var y = m.mt[m.index]
|
||||||
|
y = y xor (y shr 11'u32)
|
||||||
|
y = y xor ((7'u32 shl y) and 0x9d2c5680'u32)
|
||||||
|
y = y xor ((15'u32 shl y) and 0xefc60000'u32)
|
||||||
|
y = y xor (y shr 18'u32)
|
||||||
|
m.index = (m.index+1) mod 624
|
||||||
|
return int(y)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Test
|
||||||
|
when isMainModule:
|
||||||
|
var mt = newMersenneTwister(2525)
|
||||||
|
|
||||||
|
for i in 0..99:
|
||||||
|
echo mt.getNum
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# Nimrod's Runtime Library
|
# Nimrod's Runtime Library
|
||||||
# (c) Copyright 2012 Andreas Rumpf
|
# (c) Copyright 2013 Andreas Rumpf
|
||||||
#
|
#
|
||||||
# See the file "copying.txt", included in this
|
# See the file "copying.txt", included in this
|
||||||
# distribution, for details about the copyright.
|
# distribution, for details about the copyright.
|
||||||
|
|
@ -52,6 +52,10 @@ proc oidToString*(oid: TOid, str: cstring) =
|
||||||
inc(i)
|
inc(i)
|
||||||
str[24] = '\0'
|
str[24] = '\0'
|
||||||
|
|
||||||
|
proc `$`*(oid: TOid): string =
|
||||||
|
result = newString(25)
|
||||||
|
oidToString(oid, result)
|
||||||
|
|
||||||
var
|
var
|
||||||
incr: int
|
incr: int
|
||||||
fuzz: int32
|
fuzz: int32
|
||||||
|
|
|
||||||
|
|
@ -24,10 +24,10 @@ type
|
||||||
TProcess = object of TObject
|
TProcess = object of TObject
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
FProcessHandle: Thandle
|
FProcessHandle: Thandle
|
||||||
inputHandle, outputHandle, errorHandle: TFileHandle
|
inHandle, outHandle, errHandle: TFileHandle
|
||||||
id: THandle
|
id: THandle
|
||||||
else:
|
else:
|
||||||
inputHandle, outputHandle, errorHandle: TFileHandle
|
inHandle, outHandle, errHandle: TFileHandle
|
||||||
inStream, outStream, errStream: PStream
|
inStream, outStream, errStream: PStream
|
||||||
id: TPid
|
id: TPid
|
||||||
exitCode: cint
|
exitCode: cint
|
||||||
|
|
@ -113,23 +113,47 @@ proc peekExitCode*(p: PProcess): int {.tags: [].}
|
||||||
## return -1 if the process is still running. Otherwise the process' exit code
|
## return -1 if the process is still running. Otherwise the process' exit code
|
||||||
|
|
||||||
proc inputStream*(p: PProcess): PStream {.rtl, extern: "nosp$1", tags: [].}
|
proc inputStream*(p: PProcess): PStream {.rtl, extern: "nosp$1", tags: [].}
|
||||||
## returns ``p``'s input stream for writing to
|
## returns ``p``'s input stream for writing to.
|
||||||
##
|
##
|
||||||
## **Warning**: The returned `PStream` should not be closed manually as it
|
## **Warning**: The returned `PStream` should not be closed manually as it
|
||||||
## is closed when closing the PProcess ``p``.
|
## is closed when closing the PProcess ``p``.
|
||||||
|
|
||||||
proc outputStream*(p: PProcess): PStream {.rtl, extern: "nosp$1", tags: [].}
|
proc outputStream*(p: PProcess): PStream {.rtl, extern: "nosp$1", tags: [].}
|
||||||
## returns ``p``'s output stream for reading from
|
## returns ``p``'s output stream for reading from.
|
||||||
##
|
##
|
||||||
## **Warning**: The returned `PStream` should not be closed manually as it
|
## **Warning**: The returned `PStream` should not be closed manually as it
|
||||||
## is closed when closing the PProcess ``p``.
|
## is closed when closing the PProcess ``p``.
|
||||||
|
|
||||||
proc errorStream*(p: PProcess): PStream {.rtl, extern: "nosp$1", tags: [].}
|
proc errorStream*(p: PProcess): PStream {.rtl, extern: "nosp$1", tags: [].}
|
||||||
## returns ``p``'s output stream for reading from
|
## returns ``p``'s error stream for reading from.
|
||||||
##
|
##
|
||||||
## **Warning**: The returned `PStream` should not be closed manually as it
|
## **Warning**: The returned `PStream` should not be closed manually as it
|
||||||
## is closed when closing the PProcess ``p``.
|
## is closed when closing the PProcess ``p``.
|
||||||
|
|
||||||
|
proc inputHandle*(p: PProcess): TFileHandle {.rtl, extern: "nosp$1",
|
||||||
|
tags: [].} =
|
||||||
|
## returns ``p``'s input file handle for writing to.
|
||||||
|
##
|
||||||
|
## **Warning**: The returned `TFileHandle` should not be closed manually as
|
||||||
|
## it is closed when closing the PProcess ``p``.
|
||||||
|
result = p.inHandle
|
||||||
|
|
||||||
|
proc outputHandle*(p: PProcess): TFileHandle {.rtl, extern: "nosp$1",
|
||||||
|
tags: [].} =
|
||||||
|
## returns ``p``'s output file handle for reading from.
|
||||||
|
##
|
||||||
|
## **Warning**: The returned `TFileHandle` should not be closed manually as
|
||||||
|
## it is closed when closing the PProcess ``p``.
|
||||||
|
result = p.outHandle
|
||||||
|
|
||||||
|
proc errorHandle*(p: PProcess): TFileHandle {.rtl, extern: "nosp$1",
|
||||||
|
tags: [].} =
|
||||||
|
## returns ``p``'s error file handle for reading from.
|
||||||
|
##
|
||||||
|
## **Warning**: The returned `TFileHandle` should not be closed manually as
|
||||||
|
## it is closed when closing the PProcess ``p``.
|
||||||
|
result = p.errHandle
|
||||||
|
|
||||||
when defined(macosx) or defined(bsd):
|
when defined(macosx) or defined(bsd):
|
||||||
const
|
const
|
||||||
CTL_HW = 6
|
CTL_HW = 6
|
||||||
|
|
@ -212,8 +236,8 @@ proc execProcesses*(cmds: openArray[string],
|
||||||
inc(i)
|
inc(i)
|
||||||
if i > high(cmds): break
|
if i > high(cmds): break
|
||||||
for j in 0..m-1:
|
for j in 0..m-1:
|
||||||
if q[j] != nil: close(q[j])
|
|
||||||
result = max(waitForExit(q[j]), result)
|
result = max(waitForExit(q[j]), result)
|
||||||
|
if q[j] != nil: close(q[j])
|
||||||
else:
|
else:
|
||||||
for i in 0..high(cmds):
|
for i in 0..high(cmds):
|
||||||
var p = startCmd(cmds[i], options=options)
|
var p = startCmd(cmds[i], options=options)
|
||||||
|
|
@ -339,16 +363,16 @@ when defined(Windows) and not defined(useNimRtl):
|
||||||
HE = HO
|
HE = HO
|
||||||
else:
|
else:
|
||||||
CreatePipeHandles(HE, Si.hStdError)
|
CreatePipeHandles(HE, Si.hStdError)
|
||||||
result.inputHandle = TFileHandle(hi)
|
result.inHandle = TFileHandle(hi)
|
||||||
result.outputHandle = TFileHandle(ho)
|
result.outHandle = TFileHandle(ho)
|
||||||
result.errorHandle = TFileHandle(he)
|
result.errHandle = TFileHandle(he)
|
||||||
else:
|
else:
|
||||||
SI.hStdError = GetStdHandle(STD_ERROR_HANDLE)
|
SI.hStdError = GetStdHandle(STD_ERROR_HANDLE)
|
||||||
SI.hStdInput = GetStdHandle(STD_INPUT_HANDLE)
|
SI.hStdInput = GetStdHandle(STD_INPUT_HANDLE)
|
||||||
SI.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE)
|
SI.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE)
|
||||||
result.inputHandle = TFileHandle(si.hStdInput)
|
result.inHandle = TFileHandle(si.hStdInput)
|
||||||
result.outputHandle = TFileHandle(si.hStdOutput)
|
result.outHandle = TFileHandle(si.hStdOutput)
|
||||||
result.errorHandle = TFileHandle(si.hStdError)
|
result.errHandle = TFileHandle(si.hStdError)
|
||||||
|
|
||||||
var cmdl: cstring
|
var cmdl: cstring
|
||||||
when false: # poUseShell in options:
|
when false: # poUseShell in options:
|
||||||
|
|
@ -389,9 +413,9 @@ when defined(Windows) and not defined(useNimRtl):
|
||||||
proc close(p: PProcess) =
|
proc close(p: PProcess) =
|
||||||
when false:
|
when false:
|
||||||
# somehow this does not work on Windows:
|
# somehow this does not work on Windows:
|
||||||
discard CloseHandle(p.inputHandle)
|
discard CloseHandle(p.inHandle)
|
||||||
discard CloseHandle(p.outputHandle)
|
discard CloseHandle(p.outHandle)
|
||||||
discard CloseHandle(p.errorHandle)
|
discard CloseHandle(p.errHandle)
|
||||||
discard CloseHandle(p.FProcessHandle)
|
discard CloseHandle(p.FProcessHandle)
|
||||||
|
|
||||||
proc suspend(p: PProcess) =
|
proc suspend(p: PProcess) =
|
||||||
|
|
@ -425,13 +449,13 @@ when defined(Windows) and not defined(useNimRtl):
|
||||||
return res
|
return res
|
||||||
|
|
||||||
proc inputStream(p: PProcess): PStream =
|
proc inputStream(p: PProcess): PStream =
|
||||||
result = newFileHandleStream(p.inputHandle)
|
result = newFileHandleStream(p.inHandle)
|
||||||
|
|
||||||
proc outputStream(p: PProcess): PStream =
|
proc outputStream(p: PProcess): PStream =
|
||||||
result = newFileHandleStream(p.outputHandle)
|
result = newFileHandleStream(p.outHandle)
|
||||||
|
|
||||||
proc errorStream(p: PProcess): PStream =
|
proc errorStream(p: PProcess): PStream =
|
||||||
result = newFileHandleStream(p.errorHandle)
|
result = newFileHandleStream(p.errHandle)
|
||||||
|
|
||||||
proc execCmd(command: string): int =
|
proc execCmd(command: string): int =
|
||||||
var
|
var
|
||||||
|
|
@ -626,20 +650,20 @@ elif not defined(useNimRtl):
|
||||||
|
|
||||||
if poParentStreams in options:
|
if poParentStreams in options:
|
||||||
# does not make much sense, but better than nothing:
|
# does not make much sense, but better than nothing:
|
||||||
result.inputHandle = 0
|
result.inHandle = 0
|
||||||
result.outputHandle = 1
|
result.outHandle = 1
|
||||||
if poStdErrToStdOut in options:
|
if poStdErrToStdOut in options:
|
||||||
result.errorHandle = result.outputHandle
|
result.errHandle = result.outHandle
|
||||||
else:
|
else:
|
||||||
result.errorHandle = 2
|
result.errHandle = 2
|
||||||
else:
|
else:
|
||||||
result.inputHandle = p_stdin[writeIdx]
|
result.inHandle = p_stdin[writeIdx]
|
||||||
result.outputHandle = p_stdout[readIdx]
|
result.outHandle = p_stdout[readIdx]
|
||||||
if poStdErrToStdOut in options:
|
if poStdErrToStdOut in options:
|
||||||
result.errorHandle = result.outputHandle
|
result.errHandle = result.outHandle
|
||||||
discard close(p_stderr[readIdx])
|
discard close(p_stderr[readIdx])
|
||||||
else:
|
else:
|
||||||
result.errorHandle = p_stderr[readIdx]
|
result.errHandle = p_stderr[readIdx]
|
||||||
discard close(p_stderr[writeIdx])
|
discard close(p_stderr[writeIdx])
|
||||||
discard close(p_stdin[readIdx])
|
discard close(p_stdin[readIdx])
|
||||||
discard close(p_stdout[writeIdx])
|
discard close(p_stdout[writeIdx])
|
||||||
|
|
@ -648,9 +672,9 @@ elif not defined(useNimRtl):
|
||||||
if p.inStream != nil: close(p.inStream)
|
if p.inStream != nil: close(p.inStream)
|
||||||
if p.outStream != nil: close(p.outStream)
|
if p.outStream != nil: close(p.outStream)
|
||||||
if p.errStream != nil: close(p.errStream)
|
if p.errStream != nil: close(p.errStream)
|
||||||
discard close(p.inputHandle)
|
discard close(p.inHandle)
|
||||||
discard close(p.outputHandle)
|
discard close(p.outHandle)
|
||||||
discard close(p.errorHandle)
|
discard close(p.errHandle)
|
||||||
|
|
||||||
proc suspend(p: PProcess) =
|
proc suspend(p: PProcess) =
|
||||||
if kill(-p.id, SIGSTOP) != 0'i32: OSError(OSLastError())
|
if kill(-p.id, SIGSTOP) != 0'i32: OSError(OSLastError())
|
||||||
|
|
@ -696,17 +720,17 @@ elif not defined(useNimRtl):
|
||||||
|
|
||||||
proc inputStream(p: PProcess): PStream =
|
proc inputStream(p: PProcess): PStream =
|
||||||
if p.inStream == nil:
|
if p.inStream == nil:
|
||||||
createStream(p.inStream, p.inputHandle, fmWrite)
|
createStream(p.inStream, p.inHandle, fmWrite)
|
||||||
return p.inStream
|
return p.inStream
|
||||||
|
|
||||||
proc outputStream(p: PProcess): PStream =
|
proc outputStream(p: PProcess): PStream =
|
||||||
if p.outStream == nil:
|
if p.outStream == nil:
|
||||||
createStream(p.outStream, p.outputHandle, fmRead)
|
createStream(p.outStream, p.outHandle, fmRead)
|
||||||
return p.outStream
|
return p.outStream
|
||||||
|
|
||||||
proc errorStream(p: PProcess): PStream =
|
proc errorStream(p: PProcess): PStream =
|
||||||
if p.errStream == nil:
|
if p.errStream == nil:
|
||||||
createStream(p.errStream, p.errorHandle, fmRead)
|
createStream(p.errStream, p.errHandle, fmRead)
|
||||||
return p.errStream
|
return p.errStream
|
||||||
|
|
||||||
proc csystem(cmd: cstring): cint {.nodecl, importc: "system".}
|
proc csystem(cmd: cstring): cint {.nodecl, importc: "system".}
|
||||||
|
|
@ -717,14 +741,14 @@ elif not defined(useNimRtl):
|
||||||
proc createFdSet(fd: var TFdSet, s: seq[PProcess], m: var int) =
|
proc createFdSet(fd: var TFdSet, s: seq[PProcess], m: var int) =
|
||||||
FD_ZERO(fd)
|
FD_ZERO(fd)
|
||||||
for i in items(s):
|
for i in items(s):
|
||||||
m = max(m, int(i.outputHandle))
|
m = max(m, int(i.outHandle))
|
||||||
FD_SET(cint(i.outputHandle), fd)
|
FD_SET(cint(i.outHandle), fd)
|
||||||
|
|
||||||
proc pruneProcessSet(s: var seq[PProcess], fd: var TFdSet) =
|
proc pruneProcessSet(s: var seq[PProcess], fd: var TFdSet) =
|
||||||
var i = 0
|
var i = 0
|
||||||
var L = s.len
|
var L = s.len
|
||||||
while i < L:
|
while i < L:
|
||||||
if FD_ISSET(cint(s[i].outputHandle), fd) != 0'i32:
|
if FD_ISSET(cint(s[i].outHandle), fd) != 0'i32:
|
||||||
s[i] = s[L-1]
|
s[i] = s[L-1]
|
||||||
dec(L)
|
dec(L)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,8 @@ proc recvBuffer(s: var TScgiState, L: int) =
|
||||||
scgiError("could not read all data")
|
scgiError("could not read all data")
|
||||||
setLen(s.input, L)
|
setLen(s.input, L)
|
||||||
|
|
||||||
proc open*(s: var TScgiState, port = TPort(4000), address = "127.0.0.1") =
|
proc open*(s: var TScgiState, port = TPort(4000), address = "127.0.0.1",
|
||||||
|
reuseAddr = False) =
|
||||||
## opens a connection.
|
## opens a connection.
|
||||||
s.bufLen = 4000
|
s.bufLen = 4000
|
||||||
s.input = newString(s.buflen) # will be reused
|
s.input = newString(s.buflen) # will be reused
|
||||||
|
|
@ -104,6 +105,8 @@ proc open*(s: var TScgiState, port = TPort(4000), address = "127.0.0.1") =
|
||||||
new(s.client) # Initialise s.client for `next`
|
new(s.client) # Initialise s.client for `next`
|
||||||
if s.server == InvalidSocket: scgiError("could not open socket")
|
if s.server == InvalidSocket: scgiError("could not open socket")
|
||||||
#s.server.connect(connectionName, port)
|
#s.server.connect(connectionName, port)
|
||||||
|
if reuseAddr:
|
||||||
|
s.server.setSockOpt(OptReuseAddr, True)
|
||||||
bindAddr(s.server, port, address)
|
bindAddr(s.server, port, address)
|
||||||
listen(s.server)
|
listen(s.server)
|
||||||
|
|
||||||
|
|
@ -243,7 +246,8 @@ proc handleAccept(sock: PAsyncSocket, s: PAsyncScgiState) =
|
||||||
|
|
||||||
proc open*(handleRequest: proc (client: PAsyncSocket,
|
proc open*(handleRequest: proc (client: PAsyncSocket,
|
||||||
input: string, headers: PStringTable) {.closure.},
|
input: string, headers: PStringTable) {.closure.},
|
||||||
port = TPort(4000), address = "127.0.0.1"): PAsyncScgiState =
|
port = TPort(4000), address = "127.0.0.1",
|
||||||
|
reuseAddr = false): PAsyncScgiState =
|
||||||
## Creates an ``PAsyncScgiState`` object which serves as a SCGI server.
|
## Creates an ``PAsyncScgiState`` object which serves as a SCGI server.
|
||||||
##
|
##
|
||||||
## After the execution of ``handleRequest`` the client socket will be closed
|
## After the execution of ``handleRequest`` the client socket will be closed
|
||||||
|
|
@ -252,6 +256,8 @@ proc open*(handleRequest: proc (client: PAsyncSocket,
|
||||||
new(cres)
|
new(cres)
|
||||||
cres.asyncServer = AsyncSocket()
|
cres.asyncServer = AsyncSocket()
|
||||||
cres.asyncServer.handleAccept = proc (s: PAsyncSocket) = handleAccept(s, cres)
|
cres.asyncServer.handleAccept = proc (s: PAsyncSocket) = handleAccept(s, cres)
|
||||||
|
if reuseAddr:
|
||||||
|
cres.asyncServer.setSockOpt(OptReuseAddr, True)
|
||||||
bindAddr(cres.asyncServer, port, address)
|
bindAddr(cres.asyncServer, port, address)
|
||||||
listen(cres.asyncServer)
|
listen(cres.asyncServer)
|
||||||
cres.handleRequest = handleRequest
|
cres.handleRequest = handleRequest
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ when hostos == "solaris":
|
||||||
|
|
||||||
import os, parseutils
|
import os, parseutils
|
||||||
from times import epochTime
|
from times import epochTime
|
||||||
|
import unsigned
|
||||||
|
|
||||||
when defined(ssl):
|
when defined(ssl):
|
||||||
import openssl
|
import openssl
|
||||||
|
|
@ -62,7 +63,7 @@ const
|
||||||
|
|
||||||
type
|
type
|
||||||
TSocketImpl = object ## socket type
|
TSocketImpl = object ## socket type
|
||||||
fd: cint
|
fd: TSocketHandle
|
||||||
case isBuffered: bool # determines whether this socket is buffered.
|
case isBuffered: bool # determines whether this socket is buffered.
|
||||||
of true:
|
of true:
|
||||||
buffer: array[0..BufferSize, char]
|
buffer: array[0..BufferSize, char]
|
||||||
|
|
@ -82,7 +83,7 @@ type
|
||||||
|
|
||||||
TSocket* = ref TSocketImpl
|
TSocket* = ref TSocketImpl
|
||||||
|
|
||||||
TPort* = distinct int16 ## port type
|
TPort* = distinct uint16 ## port type
|
||||||
|
|
||||||
TDomain* = enum ## domain, which specifies the protocol family of the
|
TDomain* = enum ## domain, which specifies the protocol family of the
|
||||||
## created socket. Other domains than those that are listed
|
## created socket. Other domains than those that are listed
|
||||||
|
|
@ -118,6 +119,10 @@ type
|
||||||
length*: int
|
length*: int
|
||||||
addrList*: seq[string]
|
addrList*: seq[string]
|
||||||
|
|
||||||
|
TSOBool* = enum ## Boolean socket options.
|
||||||
|
OptAcceptConn, OptBroadcast, OptDebug, OptDontRoute, OptKeepAlive,
|
||||||
|
OptOOBInline, OptReuseAddr
|
||||||
|
|
||||||
TRecvLineResult* = enum ## result for recvLineAsync
|
TRecvLineResult* = enum ## result for recvLineAsync
|
||||||
RecvFullLine, RecvPartialLine, RecvDisconnected, RecvFail
|
RecvFullLine, RecvPartialLine, RecvDisconnected, RecvFail
|
||||||
|
|
||||||
|
|
@ -126,7 +131,19 @@ type
|
||||||
|
|
||||||
ETimeout* = object of ESynch
|
ETimeout* = object of ESynch
|
||||||
|
|
||||||
proc newTSocket(fd: int32, isBuff: bool): TSocket =
|
let
|
||||||
|
InvalidSocket*: TSocket = nil ## invalid socket
|
||||||
|
|
||||||
|
when defined(windows):
|
||||||
|
let
|
||||||
|
OSInvalidSocket = winlean.INVALID_SOCKET
|
||||||
|
else:
|
||||||
|
let
|
||||||
|
OSInvalidSocket = posix.INVALID_SOCKET
|
||||||
|
|
||||||
|
proc newTSocket(fd: TSocketHandle, isBuff: bool): TSocket =
|
||||||
|
if fd == OSInvalidSocket:
|
||||||
|
return nil
|
||||||
new(result)
|
new(result)
|
||||||
result.fd = fd
|
result.fd = fd
|
||||||
result.isBuffered = isBuff
|
result.isBuffered = isBuff
|
||||||
|
|
@ -134,15 +151,11 @@ proc newTSocket(fd: int32, isBuff: bool): TSocket =
|
||||||
result.currPos = 0
|
result.currPos = 0
|
||||||
result.nonblocking = false
|
result.nonblocking = false
|
||||||
|
|
||||||
let
|
|
||||||
InvalidSocket*: TSocket = nil ## invalid socket
|
|
||||||
|
|
||||||
proc `==`*(a, b: TPort): bool {.borrow.}
|
proc `==`*(a, b: TPort): bool {.borrow.}
|
||||||
## ``==`` for ports.
|
## ``==`` for ports.
|
||||||
|
|
||||||
proc `$`*(p: TPort): string =
|
proc `$`*(p: TPort): string {.borrow.}
|
||||||
## returns the port number as a string
|
## returns the port number as a string
|
||||||
result = $ze(int16(p))
|
|
||||||
|
|
||||||
proc ntohl*(x: int32): int32 =
|
proc ntohl*(x: int32): int32 =
|
||||||
## Converts 32-bit integers from network to host byte order.
|
## Converts 32-bit integers from network to host byte order.
|
||||||
|
|
@ -212,6 +225,8 @@ else:
|
||||||
proc socket*(domain: TDomain = AF_INET, typ: TType = SOCK_STREAM,
|
proc socket*(domain: TDomain = AF_INET, typ: TType = SOCK_STREAM,
|
||||||
protocol: TProtocol = IPPROTO_TCP, buffered = true): TSocket =
|
protocol: TProtocol = IPPROTO_TCP, buffered = true): TSocket =
|
||||||
## Creates a new socket; returns `InvalidSocket` if an error occurs.
|
## Creates a new socket; returns `InvalidSocket` if an error occurs.
|
||||||
|
|
||||||
|
# TODO: Perhaps this should just raise EOS when an error occurs.
|
||||||
when defined(Windows):
|
when defined(Windows):
|
||||||
result = newTSocket(winlean.socket(ord(domain), ord(typ), ord(protocol)), buffered)
|
result = newTSocket(winlean.socket(ord(domain), ord(typ), ord(protocol)), buffered)
|
||||||
else:
|
else:
|
||||||
|
|
@ -456,7 +471,7 @@ template acceptAddrPlain(noClientRet, successRet: expr,
|
||||||
var sock = accept(server.fd, cast[ptr TSockAddr](addr(sockAddress)),
|
var sock = accept(server.fd, cast[ptr TSockAddr](addr(sockAddress)),
|
||||||
addr(addrLen))
|
addr(addrLen))
|
||||||
|
|
||||||
if sock < 0:
|
if sock == OSInvalidSocket:
|
||||||
let err = OSLastError()
|
let err = OSLastError()
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
if err.int32 == WSAEINPROGRESS:
|
if err.int32 == WSAEINPROGRESS:
|
||||||
|
|
@ -529,7 +544,7 @@ proc acceptAddr*(server: TSocket, client: var TSocket, address: var string) {.
|
||||||
SSLError("Unknown error")
|
SSLError("Unknown error")
|
||||||
|
|
||||||
proc setBlocking*(s: TSocket, blocking: bool) {.tags: [].}
|
proc setBlocking*(s: TSocket, blocking: bool) {.tags: [].}
|
||||||
## sets blocking mode on socket
|
## Sets blocking mode on socket
|
||||||
|
|
||||||
when defined(ssl):
|
when defined(ssl):
|
||||||
proc acceptAddrSSL*(server: TSocket, client: var TSocket,
|
proc acceptAddrSSL*(server: TSocket, client: var TSocket,
|
||||||
|
|
@ -623,24 +638,32 @@ proc close*(socket: TSocket) =
|
||||||
discard SSLShutdown(socket.sslHandle)
|
discard SSLShutdown(socket.sslHandle)
|
||||||
|
|
||||||
proc getServByName*(name, proto: string): TServent {.tags: [FReadIO].} =
|
proc getServByName*(name, proto: string): TServent {.tags: [FReadIO].} =
|
||||||
## well-known getservbyname proc.
|
## Searches the database from the beginning and finds the first entry for
|
||||||
|
## which the service name specified by ``name`` matches the s_name member
|
||||||
|
## and the protocol name specified by ``proto`` matches the s_proto member.
|
||||||
|
##
|
||||||
|
## On posix this will search through the ``/etc/services`` file.
|
||||||
when defined(Windows):
|
when defined(Windows):
|
||||||
var s = winlean.getservbyname(name, proto)
|
var s = winlean.getservbyname(name, proto)
|
||||||
else:
|
else:
|
||||||
var s = posix.getservbyname(name, proto)
|
var s = posix.getservbyname(name, proto)
|
||||||
if s == nil: OSError(OSLastError())
|
if s == nil: raise newException(EOS, "Service not found.")
|
||||||
result.name = $s.s_name
|
result.name = $s.s_name
|
||||||
result.aliases = cstringArrayToSeq(s.s_aliases)
|
result.aliases = cstringArrayToSeq(s.s_aliases)
|
||||||
result.port = TPort(s.s_port)
|
result.port = TPort(s.s_port)
|
||||||
result.proto = $s.s_proto
|
result.proto = $s.s_proto
|
||||||
|
|
||||||
proc getServByPort*(port: TPort, proto: string): TServent {.tags: [FReadIO].} =
|
proc getServByPort*(port: TPort, proto: string): TServent {.tags: [FReadIO].} =
|
||||||
## well-known getservbyport proc.
|
## Searches the database from the beginning and finds the first entry for
|
||||||
|
## which the port specified by ``port`` matches the s_port member and the
|
||||||
|
## protocol name specified by ``proto`` matches the s_proto member.
|
||||||
|
##
|
||||||
|
## On posix this will search through the ``/etc/services`` file.
|
||||||
when defined(Windows):
|
when defined(Windows):
|
||||||
var s = winlean.getservbyport(ze(int16(port)).cint, proto)
|
var s = winlean.getservbyport(ze(int16(port)).cint, proto)
|
||||||
else:
|
else:
|
||||||
var s = posix.getservbyport(ze(int16(port)).cint, proto)
|
var s = posix.getservbyport(ze(int16(port)).cint, proto)
|
||||||
if s == nil: OSError(OSLastError())
|
if s == nil: raise newException(EOS, "Service not found.")
|
||||||
result.name = $s.s_name
|
result.name = $s.s_name
|
||||||
result.aliases = cstringArrayToSeq(s.s_aliases)
|
result.aliases = cstringArrayToSeq(s.s_aliases)
|
||||||
result.port = TPort(s.s_port)
|
result.port = TPort(s.s_port)
|
||||||
|
|
@ -676,7 +699,7 @@ proc getHostByAddr*(ip: string): THostEnt {.tags: [FReadIO].} =
|
||||||
result.length = int(s.h_length)
|
result.length = int(s.h_length)
|
||||||
|
|
||||||
proc getHostByName*(name: string): THostEnt {.tags: [FReadIO].} =
|
proc getHostByName*(name: string): THostEnt {.tags: [FReadIO].} =
|
||||||
## well-known gethostbyname proc.
|
## This function will lookup the IP address of a hostname.
|
||||||
when defined(Windows):
|
when defined(Windows):
|
||||||
var s = winlean.gethostbyname(name)
|
var s = winlean.gethostbyname(name)
|
||||||
else:
|
else:
|
||||||
|
|
@ -714,6 +737,34 @@ proc setSockOptInt*(socket: TSocket, level, optname, optval: int) {.
|
||||||
sizeof(value).TSockLen) < 0'i32:
|
sizeof(value).TSockLen) < 0'i32:
|
||||||
OSError(OSLastError())
|
OSError(OSLastError())
|
||||||
|
|
||||||
|
proc toCInt(opt: TSOBool): cint =
|
||||||
|
case opt
|
||||||
|
of OptAcceptConn: SO_ACCEPTCONN
|
||||||
|
of OptBroadcast: SO_BROADCAST
|
||||||
|
of OptDebug: SO_DEBUG
|
||||||
|
of OptDontRoute: SO_DONTROUTE
|
||||||
|
of OptKeepAlive: SO_KEEPALIVE
|
||||||
|
of OptOOBInline: SO_OOBINLINE
|
||||||
|
of OptReuseAddr: SO_REUSEADDR
|
||||||
|
|
||||||
|
proc getSockOpt*(socket: TSocket, opt: TSOBool, level = SOL_SOCKET): bool {.
|
||||||
|
tags: [FReadIO].} =
|
||||||
|
## Retrieves option ``opt`` as a boolean value.
|
||||||
|
var res: cint
|
||||||
|
var size = sizeof(res).TSockLen
|
||||||
|
if getsockopt(socket.fd, cint(level), toCInt(opt),
|
||||||
|
addr(res), addr(size)) < 0'i32:
|
||||||
|
OSError(OSLastError())
|
||||||
|
result = res != 0
|
||||||
|
|
||||||
|
proc setSockOpt*(socket: TSocket, opt: TSOBool, value: bool, level = SOL_SOCKET) {.
|
||||||
|
tags: [FWriteIO].} =
|
||||||
|
## Sets option ``opt`` to a boolean value specified by ``value``.
|
||||||
|
var valuei = cint(if value: 1 else: 0)
|
||||||
|
if setsockopt(socket.fd, cint(level), toCInt(opt), addr(valuei),
|
||||||
|
sizeof(valuei).TSockLen) < 0'i32:
|
||||||
|
OSError(OSLastError())
|
||||||
|
|
||||||
proc connect*(socket: TSocket, address: string, port = TPort(0),
|
proc connect*(socket: TSocket, address: string, port = TPort(0),
|
||||||
af: TDomain = AF_INET) {.tags: [FReadIO].} =
|
af: TDomain = AF_INET) {.tags: [FReadIO].} =
|
||||||
## Connects socket to ``address``:``port``. ``Address`` can be an IP address or a
|
## Connects socket to ``address``:``port``. ``Address`` can be an IP address or a
|
||||||
|
|
@ -866,11 +917,6 @@ proc timeValFromMilliseconds(timeout = 500): TTimeVal =
|
||||||
var seconds = timeout div 1000
|
var seconds = timeout div 1000
|
||||||
result.tv_sec = seconds.int32
|
result.tv_sec = seconds.int32
|
||||||
result.tv_usec = ((timeout - seconds * 1000) * 1000).int32
|
result.tv_usec = ((timeout - seconds * 1000) * 1000).int32
|
||||||
#proc recvfrom*(s: TWinSocket, buf: cstring, len, flags: cint,
|
|
||||||
# fromm: ptr TSockAddr, fromlen: ptr cint): cint
|
|
||||||
|
|
||||||
#proc sendto*(s: TWinSocket, buf: cstring, len, flags: cint,
|
|
||||||
# to: ptr TSockAddr, tolen: cint): cint
|
|
||||||
|
|
||||||
proc createFdSet(fd: var TFdSet, s: seq[TSocket], m: var int) =
|
proc createFdSet(fd: var TFdSet, s: seq[TSocket], m: var int) =
|
||||||
FD_ZERO(fd)
|
FD_ZERO(fd)
|
||||||
|
|
@ -1608,14 +1654,14 @@ when defined(Windows):
|
||||||
FIONBIO = IOC_IN.int32 or ((sizeof(int32) and IOCPARM_MASK) shl 16) or
|
FIONBIO = IOC_IN.int32 or ((sizeof(int32) and IOCPARM_MASK) shl 16) or
|
||||||
(102 shl 8) or 126
|
(102 shl 8) or 126
|
||||||
|
|
||||||
proc ioctlsocket(s: TWinSocket, cmd: clong,
|
proc ioctlsocket(s: TSocketHandle, cmd: clong,
|
||||||
argptr: ptr clong): cint {.
|
argptr: ptr clong): cint {.
|
||||||
stdcall, importc:"ioctlsocket", dynlib: "ws2_32.dll".}
|
stdcall, importc:"ioctlsocket", dynlib: "ws2_32.dll".}
|
||||||
|
|
||||||
proc setBlocking(s: TSocket, blocking: bool) =
|
proc setBlocking(s: TSocket, blocking: bool) =
|
||||||
when defined(Windows):
|
when defined(Windows):
|
||||||
var mode = clong(ord(not blocking)) # 1 for non-blocking, 0 for blocking
|
var mode = clong(ord(not blocking)) # 1 for non-blocking, 0 for blocking
|
||||||
if ioctlsocket(TWinSocket(s.fd), FIONBIO, addr(mode)) == -1:
|
if ioctlsocket(TSocketHandle(s.fd), FIONBIO, addr(mode)) == -1:
|
||||||
OSError(OSLastError())
|
OSError(OSLastError())
|
||||||
else: # BSD sockets
|
else: # BSD sockets
|
||||||
var x: int = fcntl(s.fd, F_GETFL, 0)
|
var x: int = fcntl(s.fd, F_GETFL, 0)
|
||||||
|
|
@ -1656,9 +1702,12 @@ proc connect*(socket: TSocket, address: string, port = TPort(0), timeout: int,
|
||||||
proc isSSL*(socket: TSocket): bool = return socket.isSSL
|
proc isSSL*(socket: TSocket): bool = return socket.isSSL
|
||||||
## Determines whether ``socket`` is a SSL socket.
|
## Determines whether ``socket`` is a SSL socket.
|
||||||
|
|
||||||
proc getFD*(socket: TSocket): cint = return socket.fd
|
proc getFD*(socket: TSocket): TSocketHandle = return socket.fd
|
||||||
## Returns the socket's file descriptor
|
## Returns the socket's file descriptor
|
||||||
|
|
||||||
|
proc isBlocking*(socket: TSocket): bool = not socket.nonblocking
|
||||||
|
## Determines whether ``socket`` is blocking.
|
||||||
|
|
||||||
when defined(Windows):
|
when defined(Windows):
|
||||||
var wsa: TWSADATA
|
var wsa: TWSADATA
|
||||||
if WSAStartup(0x0101'i16, addr wsa) != 0: OSError(OSLastError())
|
if WSAStartup(0x0101'i16, addr wsa) != 0: OSError(OSLastError())
|
||||||
|
|
|
||||||
|
|
@ -246,7 +246,8 @@ proc toSeconds(a: TTimeInfo, interval: TTimeInterval): float =
|
||||||
else:
|
else:
|
||||||
curMonth.inc()
|
curMonth.inc()
|
||||||
result += float(newinterv.days * 24 * 60 * 60)
|
result += float(newinterv.days * 24 * 60 * 60)
|
||||||
result += float(newinterv.minutes * 60 * 60)
|
result += float(newinterv.hours * 60 * 60)
|
||||||
|
result += float(newinterv.minutes * 60)
|
||||||
result += float(newinterv.seconds)
|
result += float(newinterv.seconds)
|
||||||
result += newinterv.miliseconds / 1000
|
result += newinterv.miliseconds / 1000
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,31 +55,31 @@ template fastRuneAt*(s: string, i: int, result: expr, doInc = true) =
|
||||||
result = TRune(ord(s[i]))
|
result = TRune(ord(s[i]))
|
||||||
when doInc: inc(i)
|
when doInc: inc(i)
|
||||||
elif ord(s[i]) shr 5 == 0b110:
|
elif ord(s[i]) shr 5 == 0b110:
|
||||||
assert(ord(s[i+1]) shr 6 == 0b10)
|
# assert(ord(s[i+1]) shr 6 == 0b10)
|
||||||
result = TRune((ord(s[i]) and (ones(5))) shl 6 or
|
result = TRune((ord(s[i]) and (ones(5))) shl 6 or
|
||||||
(ord(s[i+1]) and ones(6)))
|
(ord(s[i+1]) and ones(6)))
|
||||||
when doInc: inc(i, 2)
|
when doInc: inc(i, 2)
|
||||||
elif ord(s[i]) shr 4 == 0b1110:
|
elif ord(s[i]) shr 4 == 0b1110:
|
||||||
assert(ord(s[i+1]) shr 6 == 0b10)
|
# assert(ord(s[i+1]) shr 6 == 0b10)
|
||||||
assert(ord(s[i+2]) shr 6 == 0b10)
|
# assert(ord(s[i+2]) shr 6 == 0b10)
|
||||||
result = TRune((ord(s[i]) and ones(4)) shl 12 or
|
result = TRune((ord(s[i]) and ones(4)) shl 12 or
|
||||||
(ord(s[i+1]) and ones(6)) shl 6 or
|
(ord(s[i+1]) and ones(6)) shl 6 or
|
||||||
(ord(s[i+2]) and ones(6)))
|
(ord(s[i+2]) and ones(6)))
|
||||||
when doInc: inc(i, 3)
|
when doInc: inc(i, 3)
|
||||||
elif ord(s[i]) shr 3 == 0b11110:
|
elif ord(s[i]) shr 3 == 0b11110:
|
||||||
assert(ord(s[i+1]) shr 6 == 0b10)
|
# assert(ord(s[i+1]) shr 6 == 0b10)
|
||||||
assert(ord(s[i+2]) shr 6 == 0b10)
|
# assert(ord(s[i+2]) shr 6 == 0b10)
|
||||||
assert(ord(s[i+3]) shr 6 == 0b10)
|
# assert(ord(s[i+3]) shr 6 == 0b10)
|
||||||
result = TRune((ord(s[i]) and ones(3)) shl 18 or
|
result = TRune((ord(s[i]) and ones(3)) shl 18 or
|
||||||
(ord(s[i+1]) and ones(6)) shl 12 or
|
(ord(s[i+1]) and ones(6)) shl 12 or
|
||||||
(ord(s[i+2]) and ones(6)) shl 6 or
|
(ord(s[i+2]) and ones(6)) shl 6 or
|
||||||
(ord(s[i+3]) and ones(6)))
|
(ord(s[i+3]) and ones(6)))
|
||||||
when doInc: inc(i, 4)
|
when doInc: inc(i, 4)
|
||||||
elif ord(s[i]) shr 2 == 0b111110:
|
elif ord(s[i]) shr 2 == 0b111110:
|
||||||
assert(ord(s[i+1]) shr 6 == 0b10)
|
# assert(ord(s[i+1]) shr 6 == 0b10)
|
||||||
assert(ord(s[i+2]) shr 6 == 0b10)
|
# assert(ord(s[i+2]) shr 6 == 0b10)
|
||||||
assert(ord(s[i+3]) shr 6 == 0b10)
|
# assert(ord(s[i+3]) shr 6 == 0b10)
|
||||||
assert(ord(s[i+4]) shr 6 == 0b10)
|
# assert(ord(s[i+4]) shr 6 == 0b10)
|
||||||
result = TRune((ord(s[i]) and ones(2)) shl 24 or
|
result = TRune((ord(s[i]) and ones(2)) shl 24 or
|
||||||
(ord(s[i+1]) and ones(6)) shl 18 or
|
(ord(s[i+1]) and ones(6)) shl 18 or
|
||||||
(ord(s[i+2]) and ones(6)) shl 12 or
|
(ord(s[i+2]) and ones(6)) shl 12 or
|
||||||
|
|
@ -87,11 +87,11 @@ template fastRuneAt*(s: string, i: int, result: expr, doInc = true) =
|
||||||
(ord(s[i+4]) and ones(6)))
|
(ord(s[i+4]) and ones(6)))
|
||||||
when doInc: inc(i, 5)
|
when doInc: inc(i, 5)
|
||||||
elif ord(s[i]) shr 1 == 0b1111110:
|
elif ord(s[i]) shr 1 == 0b1111110:
|
||||||
assert(ord(s[i+1]) shr 6 == 0b10)
|
# assert(ord(s[i+1]) shr 6 == 0b10)
|
||||||
assert(ord(s[i+2]) shr 6 == 0b10)
|
# assert(ord(s[i+2]) shr 6 == 0b10)
|
||||||
assert(ord(s[i+3]) shr 6 == 0b10)
|
# assert(ord(s[i+3]) shr 6 == 0b10)
|
||||||
assert(ord(s[i+4]) shr 6 == 0b10)
|
# assert(ord(s[i+4]) shr 6 == 0b10)
|
||||||
assert(ord(s[i+5]) shr 6 == 0b10)
|
# assert(ord(s[i+5]) shr 6 == 0b10)
|
||||||
result = TRune((ord(s[i]) and ones(1)) shl 30 or
|
result = TRune((ord(s[i]) and ones(1)) shl 30 or
|
||||||
(ord(s[i+1]) and ones(6)) shl 24 or
|
(ord(s[i+1]) and ones(6)) shl 24 or
|
||||||
(ord(s[i+2]) and ones(6)) shl 18 or
|
(ord(s[i+2]) and ones(6)) shl 18 or
|
||||||
|
|
|
||||||
|
|
@ -374,10 +374,10 @@ proc newSeq*[T](s: var seq[T], len: int) {.magic: "NewSeq", noSideEffect.}
|
||||||
## This is equivalent to ``s = @[]; setlen(s, len)``, but more
|
## This is equivalent to ``s = @[]; setlen(s, len)``, but more
|
||||||
## efficient since no reallocation is needed.
|
## efficient since no reallocation is needed.
|
||||||
##
|
##
|
||||||
## Note that the sequence will be filled with uninitialized entries, which
|
## Note that the sequence will be filled with zeroed entries, which can be a
|
||||||
## can be a problem for sequences containing strings. After the creation of
|
## problem for sequences containing strings since their value will be
|
||||||
## the sequence you should assign entries to the sequence instead of adding
|
## ``nil``. After the creation of the sequence you should assign entries to
|
||||||
## them. Example:
|
## the sequence instead of adding them. Example:
|
||||||
##
|
##
|
||||||
## .. code-block:: nimrod
|
## .. code-block:: nimrod
|
||||||
## var inputStrings : seq[string]
|
## var inputStrings : seq[string]
|
||||||
|
|
@ -390,10 +390,10 @@ proc newSeq*[T](s: var seq[T], len: int) {.magic: "NewSeq", noSideEffect.}
|
||||||
proc newSeq*[T](len = 0): seq[T] =
|
proc newSeq*[T](len = 0): seq[T] =
|
||||||
## creates a new sequence of type ``seq[T]`` with length ``len``.
|
## creates a new sequence of type ``seq[T]`` with length ``len``.
|
||||||
##
|
##
|
||||||
## Note that the sequence will be filled with uninitialized entries, which
|
## Note that the sequence will be filled with zeroed entries, which can be a
|
||||||
## can be a problem for sequences containing strings. After the creation of
|
## problem for sequences containing strings since their value will be
|
||||||
## the sequence you should assign entries to the sequence instead of adding
|
## ``nil``. After the creation of the sequence you should assign entries to
|
||||||
## them. Example:
|
## the sequence instead of adding them. Example:
|
||||||
##
|
##
|
||||||
## .. code-block:: nimrod
|
## .. code-block:: nimrod
|
||||||
## var inputStrings = newSeq[string](3)
|
## var inputStrings = newSeq[string](3)
|
||||||
|
|
@ -849,7 +849,7 @@ const
|
||||||
## a string that describes the application type. Possible values:
|
## a string that describes the application type. Possible values:
|
||||||
## "console", "gui", "lib".
|
## "console", "gui", "lib".
|
||||||
|
|
||||||
seqShallowFlag = 1 shl (sizeof(int)*8-1)
|
seqShallowFlag = low(int)
|
||||||
|
|
||||||
proc compileOption*(option: string): bool {.
|
proc compileOption*(option: string): bool {.
|
||||||
magic: "CompileOption", noSideEffect.}
|
magic: "CompileOption", noSideEffect.}
|
||||||
|
|
@ -1795,7 +1795,7 @@ when defined(JS):
|
||||||
|
|
||||||
elif hostOS != "standalone":
|
elif hostOS != "standalone":
|
||||||
{.push stack_trace:off, profiler:off.}
|
{.push stack_trace:off, profiler:off.}
|
||||||
proc add*(x: var string, y: cstring) {.noStackFrame.} =
|
proc add*(x: var string, y: cstring) =
|
||||||
var i = 0
|
var i = 0
|
||||||
while y[i] != '\0':
|
while y[i] != '\0':
|
||||||
add(x, y[i])
|
add(x, y[i])
|
||||||
|
|
@ -2619,12 +2619,13 @@ type
|
||||||
PNimrodNode* {.magic: "PNimrodNode".} = ref TNimrodNode
|
PNimrodNode* {.magic: "PNimrodNode".} = ref TNimrodNode
|
||||||
## represents a Nimrod AST node. Macros operate on this type.
|
## represents a Nimrod AST node. Macros operate on this type.
|
||||||
|
|
||||||
template eval*(blk: stmt): stmt =
|
when false:
|
||||||
## executes a block of code at compile time just as if it was a macro
|
template eval*(blk: stmt): stmt =
|
||||||
## optionally, the block can return an AST tree that will replace the
|
## executes a block of code at compile time just as if it was a macro
|
||||||
## eval expression
|
## optionally, the block can return an AST tree that will replace the
|
||||||
macro payload: stmt {.gensym.} = blk
|
## eval expression
|
||||||
payload()
|
macro payload: stmt {.gensym.} = blk
|
||||||
|
payload()
|
||||||
|
|
||||||
when hostOS != "standalone":
|
when hostOS != "standalone":
|
||||||
proc insert*(x: var string, item: string, i = 0) {.noSideEffect.} =
|
proc insert*(x: var string, item: string, i = 0) {.noSideEffect.} =
|
||||||
|
|
|
||||||
|
|
@ -520,11 +520,18 @@ proc allocInv(a: TMemRegion): bool =
|
||||||
for s in low(a.freeSmallChunks)..high(a.freeSmallChunks):
|
for s in low(a.freeSmallChunks)..high(a.freeSmallChunks):
|
||||||
var c = a.freeSmallChunks[s]
|
var c = a.freeSmallChunks[s]
|
||||||
while c != nil:
|
while c != nil:
|
||||||
if c.next == c: return false
|
if c.next == c:
|
||||||
if c.size != s * MemAlign: return false
|
echo "[SYSASSERT] c.next == c"
|
||||||
|
return false
|
||||||
|
if c.size != s * MemAlign:
|
||||||
|
echo "[SYSASSERT] c.size != s * MemAlign"
|
||||||
|
return false
|
||||||
var it = c.freeList
|
var it = c.freeList
|
||||||
while it != nil:
|
while it != nil:
|
||||||
if it.zeroField != 0: return false
|
if it.zeroField != 0:
|
||||||
|
echo "[SYSASSERT] it.zeroField != 0"
|
||||||
|
cprintf("%ld %p\n", it.zeroField, it)
|
||||||
|
return false
|
||||||
it = it.next
|
it = it.next
|
||||||
c = c.next
|
c = c.next
|
||||||
result = true
|
result = true
|
||||||
|
|
@ -591,6 +598,7 @@ proc rawAlloc(a: var TMemRegion, requestedSize: int): pointer =
|
||||||
add(a, a.root, cast[TAddress](result), cast[TAddress](result)+%size)
|
add(a, a.root, cast[TAddress](result), cast[TAddress](result)+%size)
|
||||||
sysAssert(isAccessible(a, result), "rawAlloc 14")
|
sysAssert(isAccessible(a, result), "rawAlloc 14")
|
||||||
sysAssert(allocInv(a), "rawAlloc: end")
|
sysAssert(allocInv(a), "rawAlloc: end")
|
||||||
|
when logAlloc: cprintf("rawAlloc: %ld %p\n", requestedSize, result)
|
||||||
|
|
||||||
proc rawAlloc0(a: var TMemRegion, requestedSize: int): pointer =
|
proc rawAlloc0(a: var TMemRegion, requestedSize: int): pointer =
|
||||||
result = rawAlloc(a, requestedSize)
|
result = rawAlloc(a, requestedSize)
|
||||||
|
|
@ -638,6 +646,7 @@ proc rawDealloc(a: var TMemRegion, p: pointer) =
|
||||||
del(a, a.root, cast[int](addr(c.data)))
|
del(a, a.root, cast[int](addr(c.data)))
|
||||||
freeBigChunk(a, c)
|
freeBigChunk(a, c)
|
||||||
sysAssert(allocInv(a), "rawDealloc: end")
|
sysAssert(allocInv(a), "rawDealloc: end")
|
||||||
|
when logAlloc: cprintf("rawDealloc: %p\n", p)
|
||||||
|
|
||||||
proc isAllocatedPtr(a: TMemRegion, p: pointer): bool =
|
proc isAllocatedPtr(a: TMemRegion, p: pointer): bool =
|
||||||
if isAccessible(a, p):
|
if isAccessible(a, p):
|
||||||
|
|
|
||||||
|
|
@ -9,68 +9,207 @@
|
||||||
|
|
||||||
# Atomic operations for Nimrod.
|
# Atomic operations for Nimrod.
|
||||||
|
|
||||||
when (defined(gcc) or defined(llvm_gcc)) and hasThreadSupport and
|
when (defined(gcc) or defined(llvm_gcc)) and hasThreadSupport:
|
||||||
not defined(windows):
|
|
||||||
proc sync_add_and_fetch(p: var int, val: int): int {.
|
type
|
||||||
importc: "__sync_add_and_fetch", nodecl.}
|
AtomMemModel* = enum
|
||||||
proc sync_sub_and_fetch(p: var int, val: int): int {.
|
ATOMIC_RELAXED,
|
||||||
importc: "__sync_sub_and_fetch", nodecl.}
|
## No barriers or synchronization.
|
||||||
|
ATOMIC_CONSUME,
|
||||||
|
## Data dependency only for both barrier and synchronization with another thread.
|
||||||
|
ATOMIC_ACQUIRE,
|
||||||
|
## Barrier to hoisting of code and synchronizes with release (or stronger)
|
||||||
|
## semantic stores from another thread.
|
||||||
|
ATOMIC_RELEASE,
|
||||||
|
## Barrier to sinking of code and synchronizes with acquire (or stronger)
|
||||||
|
## semantic loads from another thread.
|
||||||
|
ATOMIC_ACQ_REL,
|
||||||
|
## Full barrier in both directions and synchronizes with acquire loads
|
||||||
|
## and release stores in another thread.
|
||||||
|
ATOMIC_SEQ_CST
|
||||||
|
## Full barrier in both directions and synchronizes with acquire loads
|
||||||
|
## and release stores in all threads.
|
||||||
|
|
||||||
|
TAtomType* = TNumber|pointer|ptr|char
|
||||||
|
## Type Class representing valid types for use with atomic procs
|
||||||
|
|
||||||
|
proc atomic_load_n*[T: TAtomType](p: ptr T, mem: AtomMemModel): T {.
|
||||||
|
importc: "__atomic_load_n", nodecl.}
|
||||||
|
## This proc implements an atomic load operation. It returns the contents at p.
|
||||||
|
## ATOMIC_RELAXED, ATOMIC_SEQ_CST, ATOMIC_ACQUIRE, ATOMIC_CONSUME.
|
||||||
|
|
||||||
|
proc atomic_load*[T: TAtomType](p: ptr T, ret: ptr T, mem: AtomMemModel) {.
|
||||||
|
importc: "__atomic_load", nodecl.}
|
||||||
|
## This is the generic version of an atomic load. It returns the contents at p in ret.
|
||||||
|
|
||||||
|
proc atomic_store_n*[T: TAtomType](p: ptr T, val: T, mem: AtomMemModel) {.
|
||||||
|
importc: "__atomic_store_n", nodecl.}
|
||||||
|
## This proc implements an atomic store operation. It writes val at p.
|
||||||
|
## ATOMIC_RELAXED, ATOMIC_SEQ_CST, and ATOMIC_RELEASE.
|
||||||
|
|
||||||
|
proc atomic_store*[T: TAtomType](p: ptr T, val: ptr T, mem: AtomMemModel) {.
|
||||||
|
importc: "__atomic_store", nodecl.}
|
||||||
|
## This is the generic version of an atomic store. It stores the value of val at p
|
||||||
|
|
||||||
|
proc atomic_exchange_n*[T: TAtomType](p: ptr T, val: T, mem: AtomMemModel): T {.
|
||||||
|
importc: "__atomic_exchange_n", nodecl.}
|
||||||
|
## This proc implements an atomic exchange operation. It writes val at p,
|
||||||
|
## and returns the previous contents at p.
|
||||||
|
## ATOMIC_RELAXED, ATOMIC_SEQ_CST, ATOMIC_ACQUIRE, ATOMIC_RELEASE, ATOMIC_ACQ_REL
|
||||||
|
|
||||||
|
proc atomic_exchange*[T: TAtomType](p: ptr T, val: ptr T, ret: ptr T, mem: AtomMemModel) {.
|
||||||
|
importc: "__atomic_exchange", nodecl.}
|
||||||
|
## This is the generic version of an atomic exchange. It stores the contents at val at p.
|
||||||
|
## The original value at p is copied into ret.
|
||||||
|
|
||||||
|
proc atomic_compare_exchange_n*[T: TAtomType](p: ptr T, expected: ptr T, desired: T,
|
||||||
|
weak: bool, success_memmodel: AtomMemModel, failure_memmodel: AtomMemModel): bool {.
|
||||||
|
importc: "__atomic_compare_exchange_n ", nodecl.}
|
||||||
|
## This proc implements an atomic compare and exchange operation. This compares the
|
||||||
|
## contents at p with the contents at expected and if equal, writes desired at p.
|
||||||
|
## If they are not equal, the current contents at p is written into expected.
|
||||||
|
## Weak is true for weak compare_exchange, and false for the strong variation.
|
||||||
|
## Many targets only offer the strong variation and ignore the parameter.
|
||||||
|
## When in doubt, use the strong variation.
|
||||||
|
## True is returned if desired is written at p and the execution is considered
|
||||||
|
## to conform to the memory model specified by success_memmodel. There are no
|
||||||
|
## restrictions on what memory model can be used here. False is returned otherwise,
|
||||||
|
## and the execution is considered to conform to failure_memmodel. This memory model
|
||||||
|
## cannot be __ATOMIC_RELEASE nor __ATOMIC_ACQ_REL. It also cannot be a stronger model
|
||||||
|
## than that specified by success_memmodel.
|
||||||
|
|
||||||
|
proc atomic_compare_exchange*[T: TAtomType](p: ptr T, expected: ptr T, desired: ptr T,
|
||||||
|
weak: bool, success_memmodel: AtomMemModel, failure_memmodel: AtomMemModel): bool {.
|
||||||
|
importc: "__atomic_compare_exchange_n ", nodecl.}
|
||||||
|
## This proc implements the generic version of atomic_compare_exchange.
|
||||||
|
## The proc is virtually identical to atomic_compare_exchange_n, except the desired
|
||||||
|
## value is also a pointer.
|
||||||
|
|
||||||
|
## Perform the operation return the new value, all memory models are valid
|
||||||
|
proc atomic_add_fetch*[T: TAtomType](p: ptr T, val: T, mem: AtomMemModel): T {.
|
||||||
|
importc: "__atomic_add_fetch", nodecl.}
|
||||||
|
proc atomic_sub_fetch*[T: TAtomType](p: ptr T, val: T, mem: AtomMemModel): T {.
|
||||||
|
importc: "__atomic_sub_fetch", nodecl.}
|
||||||
|
proc atomic_or_fetch*[T: TAtomType](p: ptr T, val: T, mem: AtomMemModel): T {.
|
||||||
|
importc: "__atomic_or_fetch ", nodecl.}
|
||||||
|
proc atomic_and_fetch*[T: TAtomType](p: ptr T, val: T, mem: AtomMemModel): T {.
|
||||||
|
importc: "__atomic_and_fetch", nodecl.}
|
||||||
|
proc atomic_xor_fetch*[T: TAtomType](p: ptr T, val: T, mem: AtomMemModel): T {.
|
||||||
|
importc: "__atomic_xor_fetch", nodecl.}
|
||||||
|
proc atomic_nand_fetch*[T: TAtomType](p: ptr T, val: T, mem: AtomMemModel): T {.
|
||||||
|
importc: "__atomic_nand_fetch ", nodecl.}
|
||||||
|
|
||||||
|
## Perform the operation return the old value, all memory models are valid
|
||||||
|
proc atomic_fetch_add*[T: TAtomType](p: ptr T, val: T, mem: AtomMemModel): T {.
|
||||||
|
importc: "__atomic_fetch_add ", nodecl.}
|
||||||
|
proc atomic_fetch_sub*[T: TAtomType](p: ptr T, val: T, mem: AtomMemModel): T {.
|
||||||
|
importc: "__atomic_fetch_sub ", nodecl.}
|
||||||
|
proc atomic_fetch_or*[T: TAtomType](p: ptr T, val: T, mem: AtomMemModel): T {.
|
||||||
|
importc: "__atomic_fetch_or ", nodecl.}
|
||||||
|
proc atomic_fetch_and*[T: TAtomType](p: ptr T, val: T, mem: AtomMemModel): T {.
|
||||||
|
importc: "__atomic_fetch_and ", nodecl.}
|
||||||
|
proc atomic_fetch_xor*[T: TAtomType](p: ptr T, val: T, mem: AtomMemModel): T {.
|
||||||
|
importc: "__atomic_fetch_xor ", nodecl.}
|
||||||
|
proc atomic_fetch_nand*[T: TAtomType](p: ptr T, val: T, mem: AtomMemModel): T {.
|
||||||
|
importc: "__atomic_fetch_nand", nodecl.}
|
||||||
|
|
||||||
|
proc atomic_test_and_set*(p: pointer, mem: AtomMemModel): bool {.
|
||||||
|
importc: "__atomic_test_and_set ", nodecl.}
|
||||||
|
## This built-in function performs an atomic test-and-set operation on the byte at p.
|
||||||
|
## The byte is set to some implementation defined nonzero “set” value and the return
|
||||||
|
## value is true if and only if the previous contents were “set”.
|
||||||
|
## All memory models are valid.
|
||||||
|
|
||||||
|
proc atomic_clear*(p: pointer, mem: AtomMemModel) {.
|
||||||
|
importc: "__atomic_clear", nodecl.}
|
||||||
|
## This built-in function performs an atomic clear operation at p.
|
||||||
|
## After the operation, at p contains 0.
|
||||||
|
## ATOMIC_RELAXED, ATOMIC_SEQ_CST, ATOMIC_RELEASE
|
||||||
|
|
||||||
|
proc atomic_thread_fence*(mem: AtomMemModel) {.
|
||||||
|
importc: "__atomic_thread_fence ", nodecl.}
|
||||||
|
## This built-in function acts as a synchronization fence between threads based
|
||||||
|
## on the specified memory model. All memory orders are valid.
|
||||||
|
|
||||||
|
proc atomic_signal_fence*(mem: AtomMemModel) {.
|
||||||
|
importc: "__atomic_signal_fence ", nodecl.}
|
||||||
|
## This built-in function acts as a synchronization fence between a thread and
|
||||||
|
## signal handlers based in the same thread. All memory orders are valid.
|
||||||
|
|
||||||
|
proc atomic_always_lock_free*(size: int, p: pointer): bool {.
|
||||||
|
importc: "__atomic_always_lock_free ", nodecl.}
|
||||||
|
## This built-in function returns true if objects of size bytes always generate
|
||||||
|
## lock free atomic instructions for the target architecture. size must resolve
|
||||||
|
## to a compile-time constant and the result also resolves to a compile-time constant.
|
||||||
|
## ptr is an optional pointer to the object that may be used to determine alignment.
|
||||||
|
## A value of 0 indicates typical alignment should be used. The compiler may also
|
||||||
|
## ignore this parameter.
|
||||||
|
|
||||||
|
proc atomic_is_lock_free*(size: int, p: pointer): bool {.
|
||||||
|
importc: "__atomic_is_lock_free ", nodecl.}
|
||||||
|
## This built-in function returns true if objects of size bytes always generate
|
||||||
|
## lock free atomic instructions for the target architecture. If it is not known
|
||||||
|
## to be lock free a call is made to a runtime routine named __atomic_is_lock_free.
|
||||||
|
## ptr is an optional pointer to the object that may be used to determine alignment.
|
||||||
|
## A value of 0 indicates typical alignment should be used. The compiler may also
|
||||||
|
## ignore this parameter.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
elif defined(vcc) and hasThreadSupport:
|
elif defined(vcc) and hasThreadSupport:
|
||||||
proc sync_add_and_fetch(p: var int, val: int): int {.
|
proc add_and_fetch*(p: ptr int, val: int): int {.
|
||||||
importc: "NimXadd", nodecl.}
|
importc: "NimXadd", nodecl.}
|
||||||
else:
|
else:
|
||||||
proc sync_add_and_fetch(p: var int, val: int): int {.inline.} =
|
proc add_and_fetch*(p: ptr int, val: int): int {.inline.} =
|
||||||
inc(p, val)
|
inc(p[], val)
|
||||||
result = p
|
result = p[]
|
||||||
|
|
||||||
proc atomicInc(memLoc: var int, x: int = 1): int =
|
|
||||||
when hasThreadSupport:
|
|
||||||
result = sync_add_and_fetch(memLoc, x)
|
|
||||||
|
# atomic compare and swap (CAS) funcitons to implement lock-free algorithms
|
||||||
|
|
||||||
|
#if defined(windows) and not defined(gcc) and hasThreadSupport:
|
||||||
|
# proc InterlockedCompareExchangePointer(mem: ptr pointer,
|
||||||
|
# newValue: pointer, comparand: pointer) : pointer {.nodecl,
|
||||||
|
# importc: "InterlockedCompareExchangePointer", header:"windows.h".}
|
||||||
|
|
||||||
|
# proc compareAndSwap*[T](mem: ptr T,
|
||||||
|
# expected: T, newValue: T): bool {.inline.}=
|
||||||
|
# ## Returns true if successfully set value at mem to newValue when value
|
||||||
|
# ## at mem == expected
|
||||||
|
# return InterlockedCompareExchangePointer(addr(mem),
|
||||||
|
# addr(newValue), addr(expected))[] == expected
|
||||||
|
|
||||||
|
#elif not hasThreadSupport:
|
||||||
|
# proc compareAndSwap*[T](mem: ptr T,
|
||||||
|
# expected: T, newValue: T): bool {.inline.} =
|
||||||
|
# ## Returns true if successfully set value at mem to newValue when value
|
||||||
|
# ## at mem == expected
|
||||||
|
# var oldval = mem[]
|
||||||
|
# if oldval == expected:
|
||||||
|
# mem[] = newValue
|
||||||
|
# return true
|
||||||
|
# return false
|
||||||
|
|
||||||
|
|
||||||
|
# Some convenient functions
|
||||||
|
proc atomicInc*(memLoc: var int, x: int = 1): int =
|
||||||
|
when defined(gcc) and hasThreadSupport:
|
||||||
|
result = atomic_add_fetch(memLoc.addr, x, ATOMIC_RELAXED)
|
||||||
else:
|
else:
|
||||||
inc(memLoc, x)
|
inc(memLoc, x)
|
||||||
result = memLoc
|
result = memLoc
|
||||||
|
|
||||||
proc atomicDec(memLoc: var int, x: int = 1): int =
|
proc atomicDec*(memLoc: var int, x: int = 1): int =
|
||||||
when hasThreadSupport:
|
when defined(gcc) and hasThreadSupport:
|
||||||
when defined(sync_sub_and_fetch):
|
when defined(atomic_sub_fetch):
|
||||||
result = sync_sub_and_fetch(memLoc, x)
|
result = atomic_sub_fetch(memLoc.addr, x, ATOMIC_RELAXED)
|
||||||
else:
|
else:
|
||||||
result = sync_add_and_fetch(memLoc, -x)
|
result = atomic_add_fetch(memLoc.addr, -x, ATOMIC_RELAXED)
|
||||||
else:
|
else:
|
||||||
dec(memLoc, x)
|
dec(memLoc, x)
|
||||||
result = memLoc
|
result = memLoc
|
||||||
|
|
||||||
|
|
||||||
# atomic compare and swap (CAS) funcitons to implement lock-free algorithms
|
|
||||||
|
|
||||||
when (defined(gcc) or defined(llvm_gcc)) and hasThreadSupport:
|
|
||||||
proc compareAndSwap*[T: ptr|ref|pointer](mem: var T, expected: T, newValue: T): bool {.nodecl,
|
|
||||||
importc: " __sync_bool_compare_and_swap".}
|
|
||||||
## Returns true if successfully set value at mem to newValue when value
|
|
||||||
## at mem == expected
|
|
||||||
|
|
||||||
elif defined(windows) and hasThreadSupport:
|
|
||||||
proc InterlockedCompareExchangePointer(mem: ptr pointer,
|
|
||||||
newValue: pointer, comparand: pointer) : pointer {.nodecl,
|
|
||||||
importc: "InterlockedCompareExchangePointer", header:"windows.h".}
|
|
||||||
|
|
||||||
|
|
||||||
proc compareAndSwap*[T: ptr|ref|pointer](mem: var T,
|
|
||||||
expected: T, newValue: T): bool {.inline.}=
|
|
||||||
## Returns true if successfully set value at mem to newValue when value
|
|
||||||
## at mem == expected
|
|
||||||
return InterlockedCompareExchangePointer(addr(mem),
|
|
||||||
newValue, expected) == expected
|
|
||||||
|
|
||||||
elif not hasThreadSupport:
|
|
||||||
proc compareAndSwap*[T: ptr|ref|pointer](mem: var T,
|
|
||||||
expected: T, newValue: T): bool {.inline.} =
|
|
||||||
## Returns true if successfully set value at mem to newValue when value
|
|
||||||
## at mem == expected
|
|
||||||
var oldval = mem
|
|
||||||
if oldval == expected:
|
|
||||||
mem = newValue
|
|
||||||
return true
|
|
||||||
return false
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,9 @@
|
||||||
## **Note:** The current implementation of message passing is slow and does
|
## **Note:** The current implementation of message passing is slow and does
|
||||||
## not work with cyclic data structures.
|
## not work with cyclic data structures.
|
||||||
|
|
||||||
|
when not defined(NimString):
|
||||||
|
{.error: "You must not import this module explicitly".}
|
||||||
|
|
||||||
type
|
type
|
||||||
pbytes = ptr array[0.. 0xffff, byte]
|
pbytes = ptr array[0.. 0xffff, byte]
|
||||||
TRawChannel {.pure, final.} = object ## msg queue for a thread
|
TRawChannel {.pure, final.} = object ## msg queue for a thread
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
# Garbage Collector
|
# Garbage Collector
|
||||||
#
|
#
|
||||||
# The basic algorithm is *Deferrent Reference Counting* with cycle detection.
|
# The basic algorithm is *Deferred Reference Counting* with cycle detection.
|
||||||
# This is achieved by combining a Deutsch-Bobrow garbage collector
|
# This is achieved by combining a Deutsch-Bobrow garbage collector
|
||||||
# together with Christoper's partial mark-sweep garbage collector.
|
# together with Christoper's partial mark-sweep garbage collector.
|
||||||
#
|
#
|
||||||
|
|
@ -407,12 +407,17 @@ proc addNewObjToZCT(res: PCell, gch: var TGcHeap) {.inline.} =
|
||||||
return
|
return
|
||||||
add(gch.zct, res)
|
add(gch.zct, res)
|
||||||
|
|
||||||
|
{.push stackTrace: off, profiler:off.}
|
||||||
|
proc gcInvariant*(msg: string) =
|
||||||
|
sysAssert(allocInv(gch.region), msg)
|
||||||
|
{.pop.}
|
||||||
|
|
||||||
proc rawNewObj(typ: PNimType, size: int, gch: var TGcHeap): pointer =
|
proc rawNewObj(typ: PNimType, size: int, gch: var TGcHeap): pointer =
|
||||||
# generates a new object and sets its reference counter to 0
|
# generates a new object and sets its reference counter to 0
|
||||||
|
sysAssert(allocInv(gch.region), "rawNewObj begin")
|
||||||
acquire(gch)
|
acquire(gch)
|
||||||
gcAssert(typ.kind in {tyRef, tyString, tySequence}, "newObj: 1")
|
gcAssert(typ.kind in {tyRef, tyString, tySequence}, "newObj: 1")
|
||||||
collectCT(gch)
|
collectCT(gch)
|
||||||
sysAssert(allocInv(gch.region), "rawNewObj begin")
|
|
||||||
var res = cast[PCell](rawAlloc(gch.region, size + sizeof(TCell)))
|
var res = cast[PCell](rawAlloc(gch.region, size + sizeof(TCell)))
|
||||||
gcAssert((cast[TAddress](res) and (MemAlign-1)) == 0, "newObj: 2")
|
gcAssert((cast[TAddress](res) and (MemAlign-1)) == 0, "newObj: 2")
|
||||||
# now it is buffered in the ZCT
|
# now it is buffered in the ZCT
|
||||||
|
|
@ -517,7 +522,9 @@ proc growObj(old: pointer, newsize: int, gch: var TGcHeap): pointer =
|
||||||
writeCell("growObj new cell", res)
|
writeCell("growObj new cell", res)
|
||||||
gcTrace(ol, csZctFreed)
|
gcTrace(ol, csZctFreed)
|
||||||
gcTrace(res, csAllocated)
|
gcTrace(res, csAllocated)
|
||||||
when reallyDealloc: rawDealloc(gch.region, ol)
|
when reallyDealloc:
|
||||||
|
sysAssert(allocInv(gch.region), "growObj before dealloc")
|
||||||
|
rawDealloc(gch.region, ol)
|
||||||
else:
|
else:
|
||||||
sysAssert(ol.typ != nil, "growObj: 5")
|
sysAssert(ol.typ != nil, "growObj: 5")
|
||||||
zeroMem(ol, sizeof(TCell))
|
zeroMem(ol, sizeof(TCell))
|
||||||
|
|
@ -537,7 +544,9 @@ proc freeCyclicCell(gch: var TGcHeap, c: PCell) =
|
||||||
prepareDealloc(c)
|
prepareDealloc(c)
|
||||||
gcTrace(c, csCycFreed)
|
gcTrace(c, csCycFreed)
|
||||||
when logGC: writeCell("cycle collector dealloc cell", c)
|
when logGC: writeCell("cycle collector dealloc cell", c)
|
||||||
when reallyDealloc: rawDealloc(gch.region, c)
|
when reallyDealloc:
|
||||||
|
sysAssert(allocInv(gch.region), "free cyclic cell")
|
||||||
|
rawDealloc(gch.region, c)
|
||||||
else:
|
else:
|
||||||
gcAssert(c.typ != nil, "freeCyclicCell")
|
gcAssert(c.typ != nil, "freeCyclicCell")
|
||||||
zeroMem(c, sizeof(TCell))
|
zeroMem(c, sizeof(TCell))
|
||||||
|
|
@ -620,7 +629,6 @@ proc doOperation(p: pointer, op: TWalkOp) =
|
||||||
case op
|
case op
|
||||||
of waZctDecRef:
|
of waZctDecRef:
|
||||||
#if not isAllocatedPtr(gch.region, c):
|
#if not isAllocatedPtr(gch.region, c):
|
||||||
# return
|
|
||||||
# c_fprintf(c_stdout, "[GC] decref bug: %p", c)
|
# c_fprintf(c_stdout, "[GC] decref bug: %p", c)
|
||||||
gcAssert(isAllocatedPtr(gch.region, c), "decRef: waZctDecRef")
|
gcAssert(isAllocatedPtr(gch.region, c), "decRef: waZctDecRef")
|
||||||
gcAssert(c.refcount >=% rcIncrement, "doOperation 2")
|
gcAssert(c.refcount >=% rcIncrement, "doOperation 2")
|
||||||
|
|
@ -910,7 +918,9 @@ proc collectZCT(gch: var TGcHeap): bool =
|
||||||
# access invalid memory. This is done by prepareDealloc():
|
# access invalid memory. This is done by prepareDealloc():
|
||||||
prepareDealloc(c)
|
prepareDealloc(c)
|
||||||
forAllChildren(c, waZctDecRef)
|
forAllChildren(c, waZctDecRef)
|
||||||
when reallyDealloc: rawDealloc(gch.region, c)
|
when reallyDealloc:
|
||||||
|
sysAssert(allocInv(gch.region), "collectZCT: rawDealloc")
|
||||||
|
rawDealloc(gch.region, c)
|
||||||
else:
|
else:
|
||||||
sysAssert(c.typ != nil, "collectZCT 2")
|
sysAssert(c.typ != nil, "collectZCT 2")
|
||||||
zeroMem(c, sizeof(TCell))
|
zeroMem(c, sizeof(TCell))
|
||||||
|
|
|
||||||
|
|
@ -387,8 +387,7 @@ template `--`(rc: TRefCount): expr =
|
||||||
rc <% rcIncrement
|
rc <% rcIncrement
|
||||||
|
|
||||||
template `--` (rc: TRefCount, heapType: THeapType): expr =
|
template `--` (rc: TRefCount, heapType: THeapType): expr =
|
||||||
(when heapType == SharedHeap: atomicDec(rc, rcIncrement) <% rcIncrement
|
(when heapType == SharedHeap: atomicDec(rc, rcIncrement) <% rcIncrement else: --rc)
|
||||||
else: --rc)
|
|
||||||
|
|
||||||
template doDecRef(cc: PCell,
|
template doDecRef(cc: PCell,
|
||||||
heapType = LocalHeap,
|
heapType = LocalHeap,
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ const
|
||||||
reallyOsDealloc = true
|
reallyOsDealloc = true
|
||||||
coalescRight = true
|
coalescRight = true
|
||||||
coalescLeft = true
|
coalescLeft = true
|
||||||
|
logAlloc = false
|
||||||
|
|
||||||
type
|
type
|
||||||
PPointer = ptr pointer
|
PPointer = ptr pointer
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,9 @@
|
||||||
## createThread(thr[i], threadFunc, (i*10, i*10+5))
|
## createThread(thr[i], threadFunc, (i*10, i*10+5))
|
||||||
## joinThreads(thr)
|
## joinThreads(thr)
|
||||||
|
|
||||||
|
when not defined(NimString):
|
||||||
|
{.error: "You must not import this module explicitly".}
|
||||||
|
|
||||||
const
|
const
|
||||||
maxRegisters = 256 # don't think there is an arch with more registers
|
maxRegisters = 256 # don't think there is an arch with more registers
|
||||||
useStackMaskHack = false ## use the stack mask hack for better performance
|
useStackMaskHack = false ## use the stack mask hack for better performance
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,232 +0,0 @@
|
||||||
#
|
|
||||||
#
|
|
||||||
# Nimrod's Runtime Library
|
|
||||||
# (c) Copyright 2006 Andreas Rumpf
|
|
||||||
#
|
|
||||||
# See the file "copying.txt", included in this
|
|
||||||
# distribution, for details about the copyright.
|
|
||||||
#
|
|
||||||
# NetBIOS 3.0 interface unit
|
|
||||||
|
|
||||||
# This module contains the definitions for portable NetBIOS 3.0 support.
|
|
||||||
|
|
||||||
{.deadCodeElim: on.}
|
|
||||||
|
|
||||||
import # Data structure templates
|
|
||||||
Windows
|
|
||||||
|
|
||||||
const
|
|
||||||
NCBNAMSZ* = 16 # absolute length of a net name
|
|
||||||
MAX_LANA* = 254 # lana's in range 0 to MAX_LANA inclusive
|
|
||||||
|
|
||||||
type # Network Control Block
|
|
||||||
PNCB* = ptr TNCB
|
|
||||||
TNCBPostProc* = proc (P: PNCB) {.stdcall.}
|
|
||||||
TNCB* {.final.} = object # Structure returned to the NCB command NCBASTAT is ADAPTER_STATUS followed
|
|
||||||
# by an array of NAME_BUFFER structures.
|
|
||||||
ncb_command*: Char # command code
|
|
||||||
ncb_retcode*: Char # return code
|
|
||||||
ncb_lsn*: Char # local session number
|
|
||||||
ncb_num*: Char # number of our network name
|
|
||||||
ncb_buffer*: cstring # address of message buffer
|
|
||||||
ncb_length*: int16 # size of message buffer
|
|
||||||
ncb_callname*: array[0..NCBNAMSZ - 1, char] # blank-padded name of remote
|
|
||||||
ncb_name*: array[0..NCBNAMSZ - 1, char] # our blank-padded netname
|
|
||||||
ncb_rto*: Char # rcv timeout/retry count
|
|
||||||
ncb_sto*: Char # send timeout/sys timeout
|
|
||||||
ncb_post*: TNCBPostProc # POST routine address
|
|
||||||
ncb_lana_num*: Char # lana (adapter) number
|
|
||||||
ncb_cmd_cplt*: Char # 0xff => commmand pending
|
|
||||||
ncb_reserve*: array[0..9, Char] # reserved, used by BIOS
|
|
||||||
ncb_event*: THandle # HANDLE to Win32 event which
|
|
||||||
# will be set to the signalled
|
|
||||||
# state when an ASYNCH command
|
|
||||||
# completes
|
|
||||||
|
|
||||||
PAdapterStatus* = ptr TAdapterStatus
|
|
||||||
TAdapterStatus* {.final.} = object
|
|
||||||
adapter_address*: array[0..5, Char]
|
|
||||||
rev_major*: Char
|
|
||||||
reserved0*: Char
|
|
||||||
adapter_type*: Char
|
|
||||||
rev_minor*: Char
|
|
||||||
duration*: int16
|
|
||||||
frmr_recv*: int16
|
|
||||||
frmr_xmit*: int16
|
|
||||||
iframe_recv_err*: int16
|
|
||||||
xmit_aborts*: int16
|
|
||||||
xmit_success*: DWORD
|
|
||||||
recv_success*: DWORD
|
|
||||||
iframe_xmit_err*: int16
|
|
||||||
recv_buff_unavail*: int16
|
|
||||||
t1_timeouts*: int16
|
|
||||||
ti_timeouts*: int16
|
|
||||||
reserved1*: DWORD
|
|
||||||
free_ncbs*: int16
|
|
||||||
max_cfg_ncbs*: int16
|
|
||||||
max_ncbs*: int16
|
|
||||||
xmit_buf_unavail*: int16
|
|
||||||
max_dgram_size*: int16
|
|
||||||
pending_sess*: int16
|
|
||||||
max_cfg_sess*: int16
|
|
||||||
max_sess*: int16
|
|
||||||
max_sess_pkt_size*: int16
|
|
||||||
name_count*: int16
|
|
||||||
|
|
||||||
PNameBuffer* = ptr TNameBuffer
|
|
||||||
TNameBuffer* {.final.} = object
|
|
||||||
name*: array[0..NCBNAMSZ - 1, Char]
|
|
||||||
name_num*: Char
|
|
||||||
name_flags*: Char
|
|
||||||
|
|
||||||
|
|
||||||
const # values for name_flags bits.
|
|
||||||
NAME_FLAGS_MASK* = 0x00000087
|
|
||||||
GROUP_NAME* = 0x00000080
|
|
||||||
UNIQUE_NAME* = 0x00000000
|
|
||||||
REGISTERING* = 0x00000000
|
|
||||||
REGISTERED* = 0x00000004
|
|
||||||
DEREGISTERED* = 0x00000005
|
|
||||||
DUPLICATE* = 0x00000006
|
|
||||||
DUPLICATE_DEREG* = 0x00000007
|
|
||||||
|
|
||||||
type # Structure returned to the NCB command NCBSSTAT is SESSION_HEADER followed
|
|
||||||
# by an array of SESSION_BUFFER structures. If the NCB_NAME starts with an
|
|
||||||
# asterisk then an array of these structures is returned containing the
|
|
||||||
# status for all names.
|
|
||||||
PSessionHeader* = ptr TSessionHeader
|
|
||||||
TSessionHeader* {.final.} = object
|
|
||||||
sess_name*: Char
|
|
||||||
num_sess*: Char
|
|
||||||
rcv_dg_outstanding*: Char
|
|
||||||
rcv_any_outstanding*: Char
|
|
||||||
|
|
||||||
PSessionBuffer* = ptr TSessionBuffer
|
|
||||||
TSessionBuffer* {.final.} = object
|
|
||||||
lsn*: Char
|
|
||||||
state*: Char
|
|
||||||
local_name*: array[0..NCBNAMSZ - 1, Char]
|
|
||||||
remote_name*: array[0..NCBNAMSZ - 1, Char]
|
|
||||||
rcvs_outstanding*: Char
|
|
||||||
sends_outstanding*: Char
|
|
||||||
|
|
||||||
|
|
||||||
const # Values for state
|
|
||||||
LISTEN_OUTSTANDING* = 0x00000001
|
|
||||||
CALL_PENDING* = 0x00000002
|
|
||||||
SESSION_ESTABLISHED* = 0x00000003
|
|
||||||
HANGUP_PENDING* = 0x00000004
|
|
||||||
HANGUP_COMPLETE* = 0x00000005
|
|
||||||
SESSION_ABORTED* = 0x00000006
|
|
||||||
|
|
||||||
type # Structure returned to the NCB command NCBENUM.
|
|
||||||
# On a system containing lana's 0, 2 and 3, a structure with
|
|
||||||
# length =3, lana[0]=0, lana[1]=2 and lana[2]=3 will be returned.
|
|
||||||
PLanaEnum* = ptr TLanaEnum
|
|
||||||
TLanaEnum* {.final.} = object # Structure returned to the NCB command NCBFINDNAME is FIND_NAME_HEADER followed
|
|
||||||
# by an array of FIND_NAME_BUFFER structures.
|
|
||||||
len*: Char # Number of valid entries in lana[]
|
|
||||||
lana*: array[0..MAX_LANA, Char]
|
|
||||||
|
|
||||||
PFindNameHeader* = ptr TFindNameHeader
|
|
||||||
TFindNameHeader* {.final.} = object
|
|
||||||
node_count*: int16
|
|
||||||
reserved*: Char
|
|
||||||
unique_group*: Char
|
|
||||||
|
|
||||||
PFindNameBuffer* = ptr TFindNameBuffer
|
|
||||||
TFindNameBuffer* {.final.} = object # Structure provided with NCBACTION. The purpose of NCBACTION is to provide
|
|
||||||
# transport specific extensions to netbios.
|
|
||||||
len*: Char
|
|
||||||
access_control*: Char
|
|
||||||
frame_control*: Char
|
|
||||||
destination_addr*: array[0..5, Char]
|
|
||||||
source_addr*: array[0..5, Char]
|
|
||||||
routing_info*: array[0..17, Char]
|
|
||||||
|
|
||||||
PActionHeader* = ptr TActionHeader
|
|
||||||
TActionHeader* {.final.} = object
|
|
||||||
transport_id*: int32
|
|
||||||
action_code*: int16
|
|
||||||
reserved*: int16
|
|
||||||
|
|
||||||
|
|
||||||
const # Values for transport_id
|
|
||||||
ALL_TRANSPORTS* = "M\0\0\0"
|
|
||||||
MS_NBF* = "MNBF" # Special values and constants
|
|
||||||
|
|
||||||
const # NCB Command codes
|
|
||||||
NCBCALL* = 0x00000010 # NCB CALL
|
|
||||||
NCBLISTEN* = 0x00000011 # NCB LISTEN
|
|
||||||
NCBHANGUP* = 0x00000012 # NCB HANG UP
|
|
||||||
NCBSEND* = 0x00000014 # NCB SEND
|
|
||||||
NCBRECV* = 0x00000015 # NCB RECEIVE
|
|
||||||
NCBRECVANY* = 0x00000016 # NCB RECEIVE ANY
|
|
||||||
NCBCHAINSEND* = 0x00000017 # NCB CHAIN SEND
|
|
||||||
NCBDGSEND* = 0x00000020 # NCB SEND DATAGRAM
|
|
||||||
NCBDGRECV* = 0x00000021 # NCB RECEIVE DATAGRAM
|
|
||||||
NCBDGSENDBC* = 0x00000022 # NCB SEND BROADCAST DATAGRAM
|
|
||||||
NCBDGRECVBC* = 0x00000023 # NCB RECEIVE BROADCAST DATAGRAM
|
|
||||||
NCBADDNAME* = 0x00000030 # NCB ADD NAME
|
|
||||||
NCBDELNAME* = 0x00000031 # NCB DELETE NAME
|
|
||||||
NCBRESET* = 0x00000032 # NCB RESET
|
|
||||||
NCBASTAT* = 0x00000033 # NCB ADAPTER STATUS
|
|
||||||
NCBSSTAT* = 0x00000034 # NCB SESSION STATUS
|
|
||||||
NCBCANCEL* = 0x00000035 # NCB CANCEL
|
|
||||||
NCBADDGRNAME* = 0x00000036 # NCB ADD GROUP NAME
|
|
||||||
NCBENUM* = 0x00000037 # NCB ENUMERATE LANA NUMBERS
|
|
||||||
NCBUNLINK* = 0x00000070 # NCB UNLINK
|
|
||||||
NCBSENDNA* = 0x00000071 # NCB SEND NO ACK
|
|
||||||
NCBCHAINSENDNA* = 0x00000072 # NCB CHAIN SEND NO ACK
|
|
||||||
NCBLANSTALERT* = 0x00000073 # NCB LAN STATUS ALERT
|
|
||||||
NCBACTION* = 0x00000077 # NCB ACTION
|
|
||||||
NCBFINDNAME* = 0x00000078 # NCB FIND NAME
|
|
||||||
NCBTRACE* = 0x00000079 # NCB TRACE
|
|
||||||
ASYNCH* = 0x00000080 # high bit set = asynchronous
|
|
||||||
# NCB Return codes
|
|
||||||
NRC_GOODRET* = 0x00000000 # good return
|
|
||||||
# also returned when ASYNCH request accepted
|
|
||||||
NRC_BUFLEN* = 0x00000001 # illegal buffer length
|
|
||||||
NRC_ILLCMD* = 0x00000003 # illegal command
|
|
||||||
NRC_CMDTMO* = 0x00000005 # command timed out
|
|
||||||
NRC_INCOMP* = 0x00000006 # message incomplete, issue another command
|
|
||||||
NRC_BADDR* = 0x00000007 # illegal buffer address
|
|
||||||
NRC_SNUMOUT* = 0x00000008 # session number out of range
|
|
||||||
NRC_NORES* = 0x00000009 # no resource available
|
|
||||||
NRC_SCLOSED* = 0x0000000A # session closed
|
|
||||||
NRC_CMDCAN* = 0x0000000B # command cancelled
|
|
||||||
NRC_DUPNAME* = 0x0000000D # duplicate name
|
|
||||||
NRC_NAMTFUL* = 0x0000000E # name table full
|
|
||||||
NRC_ACTSES* = 0x0000000F # no deletions, name has active sessions
|
|
||||||
NRC_LOCTFUL* = 0x00000011 # local session table full
|
|
||||||
NRC_REMTFUL* = 0x00000012 # remote session table full
|
|
||||||
NRC_ILLNN* = 0x00000013 # illegal name number
|
|
||||||
NRC_NOCALL* = 0x00000014 # no callname
|
|
||||||
NRC_NOWILD* = 0x00000015 # cannot put * in NCB_NAME
|
|
||||||
NRC_INUSE* = 0x00000016 # name in use on remote adapter
|
|
||||||
NRC_NAMERR* = 0x00000017 # name deleted
|
|
||||||
NRC_SABORT* = 0x00000018 # session ended abnormally
|
|
||||||
NRC_NAMCONF* = 0x00000019 # name conflict detected
|
|
||||||
NRC_IFBUSY* = 0x00000021 # interface busy, IRET before retrying
|
|
||||||
NRC_TOOMANY* = 0x00000022 # too many commands outstanding, retry later
|
|
||||||
NRC_BRIDGE* = 0x00000023 # NCB_lana_num field invalid
|
|
||||||
NRC_CANOCCR* = 0x00000024 # command completed while cancel occurring
|
|
||||||
NRC_CANCEL* = 0x00000026 # command not valid to cancel
|
|
||||||
NRC_DUPENV* = 0x00000030 # name defined by anther local process
|
|
||||||
NRC_ENVNOTDEF* = 0x00000034 # environment undefined. RESET required
|
|
||||||
NRC_OSRESNOTAV* = 0x00000035 # required OS resources exhausted
|
|
||||||
NRC_MAXAPPS* = 0x00000036 # max number of applications exceeded
|
|
||||||
NRC_NOSAPS* = 0x00000037 # no saps available for netbios
|
|
||||||
NRC_NORESOURCES* = 0x00000038 # requested resources are not available
|
|
||||||
NRC_INVADDRESS* = 0x00000039 # invalid ncb address or length > segment
|
|
||||||
NRC_INVDDID* = 0x0000003B # invalid NCB DDID
|
|
||||||
NRC_LOCKFAIL* = 0x0000003C # lock of user area failed
|
|
||||||
NRC_OPENERR* = 0x0000003F # NETBIOS not loaded
|
|
||||||
NRC_SYSTEM* = 0x00000040 # system error
|
|
||||||
NRC_PENDING* = 0x000000FF # asynchronous command is not yet finished
|
|
||||||
# main user entry point for NetBIOS 3.0
|
|
||||||
# Usage: Result = Netbios( pncb );
|
|
||||||
|
|
||||||
proc Netbios*(P: PNCB): Char{.stdcall, dynlib: "netapi32.dll",
|
|
||||||
importc: "Netbios".}
|
|
||||||
# implementation
|
|
||||||
|
|
@ -1,208 +0,0 @@
|
||||||
#
|
|
||||||
#
|
|
||||||
# Nimrod's Runtime Library
|
|
||||||
# (c) Copyright 2006 Andreas Rumpf
|
|
||||||
#
|
|
||||||
# See the file "copying.txt", included in this
|
|
||||||
# distribution, for details about the copyright.
|
|
||||||
#
|
|
||||||
|
|
||||||
import
|
|
||||||
windows
|
|
||||||
|
|
||||||
const
|
|
||||||
GUID_NULL*: TGUID = (D1: 0x00000000, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000000])
|
|
||||||
IID_IUnknown*: TGUID = (D1: 0x00000000, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IClassFactory*: TGUID = (D1: 0x00000001, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IMarshal*: TGUID = (D1: 0x00000003, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IMalloc*: TGUID = (D1: 0x00000002, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IStdMarshalInfo*: TGUID = (D1: 0x00000018, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IExternalConnection*: TGUID = (D1: 0x00000019, D2: 0x00000000,
|
|
||||||
D3: 0x00000000, D4: [0x000000C0, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000000, 0x00000000, 0x00000046])
|
|
||||||
IID_IEnumUnknown*: TGUID = (D1: 0x00000100, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IBindCtx*: TGUID = (D1: 0x0000000E, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IEnumMoniker*: TGUID = (D1: 0x00000102, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IRunnableObject*: TGUID = (D1: 0x00000126, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IRunningObjectTable*: TGUID = (D1: 0x00000010, D2: 0x00000000,
|
|
||||||
D3: 0x00000000, D4: [0x000000C0, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000000, 0x00000000, 0x00000046])
|
|
||||||
IID_IPersist*: TGUID = (D1: 0x0000010C, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IPersistStream*: TGUID = (D1: 0x00000109, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IMoniker*: TGUID = (D1: 0x0000000F, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IEnumString*: TGUID = (D1: 0x00000101, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IStream*: TGUID = (D1: 0x0000000C, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IEnumStatStg*: TGUID = (D1: 0x0000000D, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IStorage*: TGUID = (D1: 0x0000000B, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IPersistFile*: TGUID = (D1: 0x0000010B, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IPersistStorage*: TGUID = (D1: 0x0000010A, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_ILockBytes*: TGUID = (D1: 0x0000000A, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IEnumFormatEtc*: TGUID = (D1: 0x00000103, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IEnumStatData*: TGUID = (D1: 0x00000105, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IRootStorage*: TGUID = (D1: 0x00000012, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IAdviseSink*: TGUID = (D1: 0x0000010F, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IAdviseSink2*: TGUID = (D1: 0x00000125, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IDataObject*: TGUID = (D1: 0x0000010E, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IDataAdviseHolder*: TGUID = (D1: 0x00000110, D2: 0x00000000,
|
|
||||||
D3: 0x00000000, D4: [0x000000C0, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000000, 0x00000000, 0x00000046])
|
|
||||||
IID_IMessageFilter*: TGUID = (D1: 0x00000016, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IRpcChannelBuffer*: TGUID = (D1: 0xD5F56B60, D2: 0x0000593B,
|
|
||||||
D3: 0x0000101A, D4: [0x000000B5, 0x00000069, 0x00000008, 0x00000000,
|
|
||||||
0x0000002B, 0x0000002D, 0x000000BF, 0x0000007A])
|
|
||||||
IID_IRpcProxyBuffer*: TGUID = (D1: 0xD5F56A34, D2: 0x0000593B, D3: 0x0000101A, D4: [
|
|
||||||
0x000000B5, 0x00000069, 0x00000008, 0x00000000, 0x0000002B, 0x0000002D,
|
|
||||||
0x000000BF, 0x0000007A])
|
|
||||||
IID_IRpcStubBuffer*: TGUID = (D1: 0xD5F56AFC, D2: 0x0000593B, D3: 0x0000101A, D4: [
|
|
||||||
0x000000B5, 0x00000069, 0x00000008, 0x00000000, 0x0000002B, 0x0000002D,
|
|
||||||
0x000000BF, 0x0000007A])
|
|
||||||
IID_IPSFactoryBuffer*: TGUID = (D1: 0xD5F569D0, D2: 0x0000593B,
|
|
||||||
D3: 0x0000101A, D4: [0x000000B5, 0x00000069, 0x00000008, 0x00000000,
|
|
||||||
0x0000002B, 0x0000002D, 0x000000BF, 0x0000007A])
|
|
||||||
IID_ICreateTypeInfo*: TGUID = (D1: 0x00020405, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_ICreateTypeLib*: TGUID = (D1: 0x00020406, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IDispatch*: TGUID = (D1: 0x00020400, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IEnumVariant*: TGUID = (D1: 0x00020404, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_ITypeComp*: TGUID = (D1: 0x00020403, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_ITypeInfo*: TGUID = (D1: 0x00020401, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_ITypeLib*: TGUID = (D1: 0x00020402, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IErrorInfo*: TGUID = (D1: 0x1CF2B120, D2: 0x0000547D, D3: 0x0000101B, D4: [
|
|
||||||
0x0000008E, 0x00000065, 0x00000008, 0x00000000, 0x0000002B, 0x0000002B,
|
|
||||||
0x000000D1, 0x00000019])
|
|
||||||
IID_ICreateErrorInfo*: TGUID = (D1: 0x22F03340, D2: 0x0000547D,
|
|
||||||
D3: 0x0000101B, D4: [0x0000008E, 0x00000065, 0x00000008, 0x00000000,
|
|
||||||
0x0000002B, 0x0000002B, 0x000000D1, 0x00000019])
|
|
||||||
IID_ISupportErrorInfo*: TGUID = (D1: 0xDF0B3D60, D2: 0x0000548F,
|
|
||||||
D3: 0x0000101B, D4: [0x0000008E, 0x00000065, 0x00000008, 0x00000000,
|
|
||||||
0x0000002B, 0x0000002B, 0x000000D1, 0x00000019])
|
|
||||||
IID_IOleAdviseHolder*: TGUID = (D1: 0x00000111, D2: 0x00000000,
|
|
||||||
D3: 0x00000000, D4: [0x000000C0, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000000, 0x00000000, 0x00000046])
|
|
||||||
IID_IOleCache*: TGUID = (D1: 0x0000011E, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IOleCache2*: TGUID = (D1: 0x00000128, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IOleCacheControl*: TGUID = (D1: 0x00000129, D2: 0x00000000,
|
|
||||||
D3: 0x00000000, D4: [0x000000C0, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000000, 0x00000000, 0x00000046])
|
|
||||||
IID_IParseDisplayName*: TGUID = (D1: 0x0000011A, D2: 0x00000000,
|
|
||||||
D3: 0x00000000, D4: [0x000000C0, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000000, 0x00000000, 0x00000046])
|
|
||||||
IID_IOleContainer*: TGUID = (D1: 0x0000011B, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IOleClientSite*: TGUID = (D1: 0x00000118, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IOleObject*: TGUID = (D1: 0x00000112, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IOleWindow*: TGUID = (D1: 0x00000114, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IOleLink*: TGUID = (D1: 0x0000011D, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IOleItemContainer*: TGUID = (D1: 0x0000011C, D2: 0x00000000,
|
|
||||||
D3: 0x00000000, D4: [0x000000C0, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000000, 0x00000000, 0x00000046])
|
|
||||||
IID_IOleInPlaceUIWindow*: TGUID = (D1: 0x00000115, D2: 0x00000000,
|
|
||||||
D3: 0x00000000, D4: [0x000000C0, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000000, 0x00000000, 0x00000046])
|
|
||||||
IID_IOleInPlaceActiveObject*: TGUID = (D1: 0x00000117, D2: 0x00000000,
|
|
||||||
D3: 0x00000000, D4: [0x000000C0, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000000, 0x00000000, 0x00000046])
|
|
||||||
IID_IOleInPlaceFrame*: TGUID = (D1: 0x00000116, D2: 0x00000000,
|
|
||||||
D3: 0x00000000, D4: [0x000000C0, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000000, 0x00000000, 0x00000046])
|
|
||||||
IID_IOleInPlaceObject*: TGUID = (D1: 0x00000113, D2: 0x00000000,
|
|
||||||
D3: 0x00000000, D4: [0x000000C0, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000000, 0x00000000, 0x00000046])
|
|
||||||
IID_IOleInPlaceSite*: TGUID = (D1: 0x00000119, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IViewObject*: TGUID = (D1: 0x0000010D, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IViewObject2*: TGUID = (D1: 0x00000127, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IDropSource*: TGUID = (D1: 0x00000121, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IDropTarget*: TGUID = (D1: 0x00000122, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
IID_IEnumOleVerb*: TGUID = (D1: 0x00000104, D2: 0x00000000, D3: 0x00000000, D4: [
|
|
||||||
0x000000C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
|
||||||
0x00000000, 0x00000046])
|
|
||||||
|
|
@ -1,202 +0,0 @@
|
||||||
#
|
|
||||||
#
|
|
||||||
# Nimrod's Runtime Library
|
|
||||||
# (c) Copyright 2009 Andreas Rumpf
|
|
||||||
#
|
|
||||||
# See the file "copying.txt", included in this
|
|
||||||
# distribution, for details about the copyright.
|
|
||||||
#
|
|
||||||
|
|
||||||
# PSAPI interface unit
|
|
||||||
|
|
||||||
# Contains the definitions for the APIs provided by PSAPI.DLL
|
|
||||||
|
|
||||||
import # Data structure templates
|
|
||||||
Windows
|
|
||||||
|
|
||||||
const
|
|
||||||
psapiDll = "psapi.dll"
|
|
||||||
|
|
||||||
proc EnumProcesses*(lpidProcess: ptr DWORD, cb: DWORD,
|
|
||||||
cbNeeded: ptr DWORD): WINBOOL {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "EnumProcesses".}
|
|
||||||
proc EnumProcessModules*(hProcess: HANDLE, lphModule: ptr HMODULE, cb: DWORD, lpcbNeeded: LPDWORD): WINBOOL {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "EnumProcessModules".}
|
|
||||||
|
|
||||||
proc GetModuleBaseNameA*(hProcess: HANDLE, hModule: HMODULE, lpBaseName: LPSTR, nSize: DWORD): DWORD {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "GetModuleBaseNameA".}
|
|
||||||
proc GetModuleBaseNameW*(hProcess: HANDLE, hModule: HMODULE, lpBaseName: LPWSTR, nSize: DWORD): DWORD {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "GetModuleBaseNameW".}
|
|
||||||
when defined(winUnicode):
|
|
||||||
proc GetModuleBaseName*(hProcess: HANDLE, hModule: HMODULE, lpBaseName: LPWSTR, nSize: DWORD): DWORD {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "GetModuleBaseNameW".}
|
|
||||||
else:
|
|
||||||
proc GetModuleBaseName*(hProcess: HANDLE, hModule: HMODULE, lpBaseName: LPSTR, nSize: DWORD): DWORD {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "GetModuleBaseNameA".}
|
|
||||||
|
|
||||||
proc GetModuleFileNameExA*(hProcess: HANDLE, hModule: HMODULE, lpFileNameEx: LPSTR, nSize: DWORD): DWORD {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "GetModuleFileNameExA".}
|
|
||||||
proc GetModuleFileNameExW*(hProcess: HANDLE, hModule: HMODULE, lpFileNameEx: LPWSTR, nSize: DWORD): DWORD {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "GetModuleFileNameExW".}
|
|
||||||
when defined(winUnicode):
|
|
||||||
proc GetModuleFileNameEx*(hProcess: HANDLE, hModule: HMODULE, lpFileNameEx: LPWSTR, nSize: DWORD): DWORD {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "GetModuleFileNameExW".}
|
|
||||||
else:
|
|
||||||
proc GetModuleFileNameEx*(hProcess: HANDLE, hModule: HMODULE, lpFileNameEx: LPSTR, nSize: DWORD): DWORD {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "GetModuleFileNameExA".}
|
|
||||||
|
|
||||||
type
|
|
||||||
MODULEINFO* {.final.} = object
|
|
||||||
lpBaseOfDll*: LPVOID
|
|
||||||
SizeOfImage*: DWORD
|
|
||||||
EntryPoint*: LPVOID
|
|
||||||
LPMODULEINFO* = ptr MODULEINFO
|
|
||||||
|
|
||||||
proc GetModuleInformation*(hProcess: HANDLE, hModule: HMODULE, lpmodinfo: LPMODULEINFO, cb: DWORD): WINBOOL {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "GetModuleInformation".}
|
|
||||||
proc EmptyWorkingSet*(hProcess: HANDLE): WINBOOL {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "EmptyWorkingSet".}
|
|
||||||
proc QueryWorkingSet*(hProcess: HANDLE, pv: PVOID, cb: DWORD): WINBOOL {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "QueryWorkingSet".}
|
|
||||||
proc QueryWorkingSetEx*(hProcess: HANDLE, pv: PVOID, cb: DWORD): WINBOOL {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "QueryWorkingSetEx".}
|
|
||||||
proc InitializeProcessForWsWatch*(hProcess: HANDLE): WINBOOL {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "InitializeProcessForWsWatch".}
|
|
||||||
|
|
||||||
type
|
|
||||||
PSAPI_WS_WATCH_INFORMATION* {.final.} = object
|
|
||||||
FaultingPc*: LPVOID
|
|
||||||
FaultingVa*: LPVOID
|
|
||||||
PPSAPI_WS_WATCH_INFORMATION* = ptr PSAPI_WS_WATCH_INFORMATION
|
|
||||||
|
|
||||||
proc GetWsChanges*(hProcess: HANDLE, lpWatchInfo: PPSAPI_WS_WATCH_INFORMATION, cb: DWORD): WINBOOL {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "GetWsChanges".}
|
|
||||||
|
|
||||||
proc GetMappedFileNameA*(hProcess: HANDLE, lpv: LPVOID, lpFilename: LPSTR, nSize: DWORD): DWORD {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "GetMappedFileNameA".}
|
|
||||||
proc GetMappedFileNameW*(hProcess: HANDLE, lpv: LPVOID, lpFilename: LPWSTR, nSize: DWORD): DWORD {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "GetMappedFileNameW".}
|
|
||||||
when defined(winUnicode):
|
|
||||||
proc GetMappedFileName*(hProcess: HANDLE, lpv: LPVOID, lpFilename: LPWSTR, nSize: DWORD): DWORD {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "GetMappedFileNameW".}
|
|
||||||
else:
|
|
||||||
proc GetMappedFileName*(hProcess: HANDLE, lpv: LPVOID, lpFilename: LPSTR, nSize: DWORD): DWORD {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "GetMappedFileNameA".}
|
|
||||||
|
|
||||||
proc EnumDeviceDrivers*(lpImageBase: LPVOID, cb: DWORD, lpcbNeeded: LPDWORD): WINBOOL {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "EnumDeviceDrivers".}
|
|
||||||
|
|
||||||
proc GetDeviceDriverBaseNameA*(ImageBase: LPVOID, lpBaseName: LPSTR, nSize: DWORD): DWORD {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "GetDeviceDriverBaseNameA".}
|
|
||||||
proc GetDeviceDriverBaseNameW*(ImageBase: LPVOID, lpBaseName: LPWSTR, nSize: DWORD): DWORD {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "GetDeviceDriverBaseNameW".}
|
|
||||||
when defined(winUnicode):
|
|
||||||
proc GetDeviceDriverBaseName*(ImageBase: LPVOID, lpBaseName: LPWSTR, nSize: DWORD): DWORD {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "GetDeviceDriverBaseNameW".}
|
|
||||||
else:
|
|
||||||
proc GetDeviceDriverBaseName*(ImageBase: LPVOID, lpBaseName: LPSTR, nSize: DWORD): DWORD {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "GetDeviceDriverBaseNameA".}
|
|
||||||
|
|
||||||
proc GetDeviceDriverFileNameA*(ImageBase: LPVOID, lpFileName: LPSTR, nSize: DWORD): DWORD {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "GetDeviceDriverFileNameA".}
|
|
||||||
proc GetDeviceDriverFileNameW*(ImageBase: LPVOID, lpFileName: LPWSTR, nSize: DWORD): DWORD {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "GetDeviceDriverFileNameW".}
|
|
||||||
when defined(winUnicode):
|
|
||||||
proc GetDeviceDriverFileName*(ImageBase: LPVOID, lpFileName: LPWSTR, nSize: DWORD): DWORD {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "GetDeviceDriverFileNameW".}
|
|
||||||
else:
|
|
||||||
proc GetDeviceDriverFileName*(ImageBase: LPVOID, lpFileName: LPSTR, nSize: DWORD): DWORD {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "GetDeviceDriverFileNameA".}
|
|
||||||
|
|
||||||
type
|
|
||||||
PROCESS_MEMORY_COUNTERS* {.final.} = object
|
|
||||||
cb*: DWORD
|
|
||||||
PageFaultCount*: DWORD
|
|
||||||
PeakWorkingSetSize: SIZE_T
|
|
||||||
WorkingSetSize: SIZE_T
|
|
||||||
QuotaPeakPagedPoolUsage: SIZE_T
|
|
||||||
QuotaPagedPoolUsage: SIZE_T
|
|
||||||
QuotaPeakNonPagedPoolUsage: SIZE_T
|
|
||||||
QuotaNonPagedPoolUsage: SIZE_T
|
|
||||||
PagefileUsage: SIZE_T
|
|
||||||
PeakPagefileUsage: SIZE_T
|
|
||||||
PPROCESS_MEMORY_COUNTERS* = ptr PROCESS_MEMORY_COUNTERS
|
|
||||||
|
|
||||||
type
|
|
||||||
PROCESS_MEMORY_COUNTERS_EX* {.final.} = object
|
|
||||||
cb*: DWORD
|
|
||||||
PageFaultCount*: DWORD
|
|
||||||
PeakWorkingSetSize: SIZE_T
|
|
||||||
WorkingSetSize: SIZE_T
|
|
||||||
QuotaPeakPagedPoolUsage: SIZE_T
|
|
||||||
QuotaPagedPoolUsage: SIZE_T
|
|
||||||
QuotaPeakNonPagedPoolUsage: SIZE_T
|
|
||||||
QuotaNonPagedPoolUsage: SIZE_T
|
|
||||||
PagefileUsage: SIZE_T
|
|
||||||
PeakPagefileUsage: SIZE_T
|
|
||||||
PrivateUsage: SIZE_T
|
|
||||||
PPROCESS_MEMORY_COUNTERS_EX* = ptr PROCESS_MEMORY_COUNTERS_EX
|
|
||||||
|
|
||||||
proc GetProcessMemoryInfo*(hProcess: HANDLE, ppsmemCounters: PPROCESS_MEMORY_COUNTERS, cb: DWORD): WINBOOL {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "GetProcessMemoryInfo".}
|
|
||||||
|
|
||||||
type
|
|
||||||
PERFORMANCE_INFORMATION* {.final.} = object
|
|
||||||
cb*: DWORD
|
|
||||||
CommitTotal: SIZE_T
|
|
||||||
CommitLimit: SIZE_T
|
|
||||||
CommitPeak: SIZE_T
|
|
||||||
PhysicalTotal: SIZE_T
|
|
||||||
PhysicalAvailable: SIZE_T
|
|
||||||
SystemCache: SIZE_T
|
|
||||||
KernelTotal: SIZE_T
|
|
||||||
KernelPaged: SIZE_T
|
|
||||||
KernelNonpaged: SIZE_T
|
|
||||||
PageSize: SIZE_T
|
|
||||||
HandleCount*: DWORD
|
|
||||||
ProcessCount*: DWORD
|
|
||||||
ThreadCount*: DWORD
|
|
||||||
PPERFORMANCE_INFORMATION* = ptr PERFORMANCE_INFORMATION
|
|
||||||
# Skip definition of PERFORMACE_INFORMATION...
|
|
||||||
|
|
||||||
proc GetPerformanceInfo*(pPerformanceInformation: PPERFORMANCE_INFORMATION, cb: DWORD): WINBOOL {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "GetPerformanceInfo".}
|
|
||||||
|
|
||||||
type
|
|
||||||
ENUM_PAGE_FILE_INFORMATION* {.final.} = object
|
|
||||||
cb*: DWORD
|
|
||||||
Reserved*: DWORD
|
|
||||||
TotalSize: SIZE_T
|
|
||||||
TotalInUse: SIZE_T
|
|
||||||
PeakUsage: SIZE_T
|
|
||||||
PENUM_PAGE_FILE_INFORMATION* = ptr ENUM_PAGE_FILE_INFORMATION
|
|
||||||
|
|
||||||
# Callback procedure
|
|
||||||
type
|
|
||||||
PENUM_PAGE_FILE_CALLBACKW* = proc (pContext: LPVOID, pPageFileInfo: PENUM_PAGE_FILE_INFORMATION, lpFilename: LPCWSTR): WINBOOL{.stdcall.}
|
|
||||||
PENUM_PAGE_FILE_CALLBACKA* = proc (pContext: LPVOID, pPageFileInfo: PENUM_PAGE_FILE_INFORMATION, lpFilename: LPCSTR): WINBOOL{.stdcall.}
|
|
||||||
|
|
||||||
#TODO
|
|
||||||
proc EnumPageFilesA*(pCallBackRoutine: PENUM_PAGE_FILE_CALLBACKA, pContext: LPVOID): WINBOOL {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "EnumPageFilesA".}
|
|
||||||
proc EnumPageFilesW*(pCallBackRoutine: PENUM_PAGE_FILE_CALLBACKW, pContext: LPVOID): WINBOOL {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "EnumPageFilesW".}
|
|
||||||
when defined(winUnicode):
|
|
||||||
proc EnumPageFiles*(pCallBackRoutine: PENUM_PAGE_FILE_CALLBACKW, pContext: LPVOID): WINBOOL {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "EnumPageFilesW".}
|
|
||||||
type PENUM_PAGE_FILE_CALLBACK* = proc (pContext: LPVOID, pPageFileInfo: PENUM_PAGE_FILE_INFORMATION, lpFilename: LPCWSTR): WINBOOL{.stdcall.}
|
|
||||||
else:
|
|
||||||
proc EnumPageFiles*(pCallBackRoutine: PENUM_PAGE_FILE_CALLBACKA, pContext: LPVOID): WINBOOL {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "EnumPageFilesA".}
|
|
||||||
type PENUM_PAGE_FILE_CALLBACK* = proc (pContext: LPVOID, pPageFileInfo: PENUM_PAGE_FILE_INFORMATION, lpFilename: LPCSTR): WINBOOL{.stdcall.}
|
|
||||||
|
|
||||||
proc GetProcessImageFileNameA*(hProcess: HANDLE, lpImageFileName: LPSTR, nSize: DWORD): DWORD {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "GetProcessImageFileNameA".}
|
|
||||||
proc GetProcessImageFileNameW*(hProcess: HANDLE, lpImageFileName: LPWSTR, nSize: DWORD): DWORD {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "GetProcessImageFileNameW".}
|
|
||||||
when defined(winUnicode):
|
|
||||||
proc GetProcessImageFileName*(hProcess: HANDLE, lpImageFileName: LPWSTR, nSize: DWORD): DWORD {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "GetProcessImageFileNameW".}
|
|
||||||
else:
|
|
||||||
proc GetProcessImageFileName*(hProcess: HANDLE, lpImageFileName: LPSTR, nSize: DWORD): DWORD {.stdcall,
|
|
||||||
dynlib: psapiDll, importc: "GetProcessImageFileNameA".}
|
|
||||||
|
|
@ -1,863 +0,0 @@
|
||||||
#
|
|
||||||
#
|
|
||||||
# Nimrod's Runtime Library
|
|
||||||
# (c) Copyright 2006 Andreas Rumpf
|
|
||||||
#
|
|
||||||
# See the file "copying.txt", included in this
|
|
||||||
# distribution, for details about the copyright.
|
|
||||||
#
|
|
||||||
|
|
||||||
{.deadCodeElim: on.}
|
|
||||||
|
|
||||||
# leave out unused functions so the unit can be used on win2000 as well
|
|
||||||
|
|
||||||
#+-------------------------------------------------------------------------
|
|
||||||
#
|
|
||||||
# Microsoft Windows
|
|
||||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
||||||
#
|
|
||||||
# File: shellapi.h
|
|
||||||
#
|
|
||||||
# Header translation by Marco van de Voort for Free Pascal Platform
|
|
||||||
# SDK dl'ed January 2002
|
|
||||||
#
|
|
||||||
#--------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#
|
|
||||||
# shellapi.h - SHELL.DLL functions, types, and definitions
|
|
||||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
||||||
|
|
||||||
import
|
|
||||||
Windows
|
|
||||||
|
|
||||||
type
|
|
||||||
HDROP* = THandle
|
|
||||||
UINT_PTR* = ptr UINT
|
|
||||||
DWORD_PTR* = ptr DWORD
|
|
||||||
pHICON* = ptr HICON
|
|
||||||
pBool* = ptr BOOL
|
|
||||||
STARTUPINFOW* {.final.} = object # a guess. Omission should get fixed in Windows.
|
|
||||||
cb*: DWORD
|
|
||||||
lpReserved*: LPTSTR
|
|
||||||
lpDesktop*: LPTSTR
|
|
||||||
lpTitle*: LPTSTR
|
|
||||||
dwX*: DWORD
|
|
||||||
dwY*: DWORD
|
|
||||||
dwXSize*: DWORD
|
|
||||||
dwYSize*: DWORD
|
|
||||||
dwXCountChars*: DWORD
|
|
||||||
dwYCountChars*: DWORD
|
|
||||||
dwFillAttribute*: DWORD
|
|
||||||
dwFlags*: DWORD
|
|
||||||
wShowWindow*: int16
|
|
||||||
cbReserved2*: int16
|
|
||||||
lpReserved2*: LPBYTE
|
|
||||||
hStdInput*: HANDLE
|
|
||||||
hStdOutput*: HANDLE
|
|
||||||
hStdError*: HANDLE
|
|
||||||
|
|
||||||
LPSTARTUPINFOW* = ptr STARTUPINFOW
|
|
||||||
TSTARTUPINFOW* = STARTUPINFOW
|
|
||||||
PSTARTUPINFOW* = ptr STARTUPINFOW #unicode
|
|
||||||
|
|
||||||
proc DragQueryFileA*(arg1: HDROP, arg2: UINT, arg3: LPSTR, arg4: UINT): UINT{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "DragQueryFileA".}
|
|
||||||
proc DragQueryFileW*(arg1: HDROP, arg2: UINT, arg3: LPWSTR, arg4: UINT): UINT{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "DragQueryFileW".}
|
|
||||||
proc DragQueryFile*(arg1: HDROP, arg2: UINT, arg3: LPSTR, arg4: UINT): UINT{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "DragQueryFileA".}
|
|
||||||
proc DragQueryFile*(arg1: HDROP, arg2: UINT, arg3: LPWSTR, arg4: UINT): UINT{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "DragQueryFileW".}
|
|
||||||
proc DragQueryPoint*(arg1: HDROP, arg2: LPPOINT): BOOL{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "DragQueryPoint".}
|
|
||||||
proc DragFinish*(arg1: HDROP){.stdcall, dynlib: "shell32.dll",
|
|
||||||
importc: "DragFinish".}
|
|
||||||
proc DragAcceptFiles*(hwnd: HWND, arg2: BOOL){.stdcall, dynlib: "shell32.dll",
|
|
||||||
importc: "DragAcceptFiles".}
|
|
||||||
proc ShellExecuteA*(HWND: hwnd, lpOperation: LPCSTR, lpFile: LPCSTR,
|
|
||||||
lpParameters: LPCSTR, lpDirectory: LPCSTR, nShowCmd: int32): HInst{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "ShellExecuteA".}
|
|
||||||
proc ShellExecuteW*(hwnd: HWND, lpOperation: LPCWSTR, lpFile: LPCWSTR,
|
|
||||||
lpParameters: LPCWSTR, lpDirectory: LPCWSTR, nShowCmd: int32): HInst{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "ShellExecuteW".}
|
|
||||||
proc ShellExecute*(HWND: hwnd, lpOperation: LPCSTR, lpFile: LPCSTR,
|
|
||||||
lpParameters: LPCSTR, lpDirectory: LPCSTR, nShowCmd: int32): HInst{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "ShellExecuteA".}
|
|
||||||
proc ShellExecute*(hwnd: HWND, lpOperation: LPCWSTR, lpFile: LPCWSTR,
|
|
||||||
lpParameters: LPCWSTR, lpDirectory: LPCWSTR, nShowCmd: int32): HInst{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "ShellExecuteW".}
|
|
||||||
proc FindExecutableA*(lpFile: LPCSTR, lpDirectory: LPCSTR, lpResult: LPSTR): HInst{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "FindExecutableA".}
|
|
||||||
proc FindExecutableW*(lpFile: LPCWSTR, lpDirectory: LPCWSTR, lpResult: LPWSTR): HInst{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "FindExecutableW".}
|
|
||||||
proc FindExecutable*(lpFile: LPCSTR, lpDirectory: LPCSTR, lpResult: LPSTR): HInst{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "FindExecutableA".}
|
|
||||||
proc FindExecutable*(lpFile: LPCWSTR, lpDirectory: LPCWSTR, lpResult: LPWSTR): HInst{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "FindExecutableW".}
|
|
||||||
proc CommandLineToArgvW*(lpCmdLine: LPCWSTR, pNumArgs: ptr int32): pLPWSTR{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "CommandLineToArgvW".}
|
|
||||||
proc ShellAboutA*(HWND: hWnd, szApp: LPCSTR, szOtherStuff: LPCSTR, HICON: hIcon): int32{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "ShellAboutA".}
|
|
||||||
proc ShellAboutW*(HWND: hWnd, szApp: LPCWSTR, szOtherStuff: LPCWSTR,
|
|
||||||
HICON: hIcon): int32{.stdcall, dynlib: "shell32.dll",
|
|
||||||
importc: "ShellAboutW".}
|
|
||||||
proc ShellAbout*(HWND: hWnd, szApp: LPCSTR, szOtherStuff: LPCSTR, HICON: hIcon): int32{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "ShellAboutA".}
|
|
||||||
proc ShellAbout*(HWND: hWnd, szApp: LPCWSTR, szOtherStuff: LPCWSTR, HICON: hIcon): int32{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "ShellAboutW".}
|
|
||||||
proc DuplicateIcon*(inst: HINST, icon: HICON): HIcon{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "DuplicateIcon".}
|
|
||||||
proc ExtractAssociatedIconA*(hInst: HINST, lpIconPath: LPSTR, lpiIcon: LPWORD): HICON{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "ExtractAssociatedIconA".}
|
|
||||||
proc ExtractAssociatedIconW*(hInst: HINST, lpIconPath: LPWSTR, lpiIcon: LPWORD): HICON{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "ExtractAssociatedIconW".}
|
|
||||||
proc ExtractAssociatedIcon*(hInst: HINST, lpIconPath: LPSTR, lpiIcon: LPWORD): HICON{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "ExtractAssociatedIconA".}
|
|
||||||
proc ExtractAssociatedIcon*(hInst: HINST, lpIconPath: LPWSTR, lpiIcon: LPWORD): HICON{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "ExtractAssociatedIconW".}
|
|
||||||
proc ExtractIconA*(hInst: HINST, lpszExeFileName: LPCSTR, nIconIndex: UINT): HICON{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "ExtractIconA".}
|
|
||||||
proc ExtractIconW*(hInst: HINST, lpszExeFileName: LPCWSTR, nIconIndex: UINT): HICON{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "ExtractIconW".}
|
|
||||||
proc ExtractIcon*(hInst: HINST, lpszExeFileName: LPCSTR, nIconIndex: UINT): HICON{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "ExtractIconA".}
|
|
||||||
proc ExtractIcon*(hInst: HINST, lpszExeFileName: LPCWSTR, nIconIndex: UINT): HICON{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "ExtractIconW".}
|
|
||||||
# if(WINVER >= 0x0400)
|
|
||||||
type # init with sizeof(DRAGINFO)
|
|
||||||
DRAGINFOA* {.final.} = object
|
|
||||||
uSize*: UINT
|
|
||||||
pt*: POINT
|
|
||||||
fNC*: BOOL
|
|
||||||
lpFileList*: LPSTR
|
|
||||||
grfKeyState*: DWORD
|
|
||||||
|
|
||||||
TDRAGINFOA* = DRAGINFOA
|
|
||||||
LPDRAGINFOA* = ptr DRAGINFOA # init with sizeof(DRAGINFO)
|
|
||||||
DRAGINFOW* {.final.} = object
|
|
||||||
uSize*: UINT
|
|
||||||
pt*: POINT
|
|
||||||
fNC*: BOOL
|
|
||||||
lpFileList*: LPWSTR
|
|
||||||
grfKeyState*: DWORD
|
|
||||||
|
|
||||||
TDRAGINFOW* = DRAGINFOW
|
|
||||||
LPDRAGINFOW* = ptr DRAGINFOW
|
|
||||||
|
|
||||||
when defined(UNICODE):
|
|
||||||
type
|
|
||||||
DRAGINFO* = DRAGINFOW
|
|
||||||
TDRAGINFO* = DRAGINFOW
|
|
||||||
LPDRAGINFO* = LPDRAGINFOW
|
|
||||||
else:
|
|
||||||
type
|
|
||||||
DRAGINFO* = DRAGINFOA
|
|
||||||
TDRAGINFO* = DRAGINFOW
|
|
||||||
LPDRAGINFO* = LPDRAGINFOA
|
|
||||||
const
|
|
||||||
ABM_NEW* = 0x00000000
|
|
||||||
ABM_REMOVE* = 0x00000001
|
|
||||||
ABM_QUERYPOS* = 0x00000002
|
|
||||||
ABM_SETPOS* = 0x00000003
|
|
||||||
ABM_GETSTATE* = 0x00000004
|
|
||||||
ABM_GETTASKBARPOS* = 0x00000005
|
|
||||||
ABM_ACTIVATE* = 0x00000006 # lParam == TRUE/FALSE means activate/deactivate
|
|
||||||
ABM_GETAUTOHIDEBAR* = 0x00000007
|
|
||||||
ABM_SETAUTOHIDEBAR* = 0x00000008 # this can fail at any time. MUST check the result
|
|
||||||
# lParam = TRUE/FALSE Set/Unset
|
|
||||||
# uEdge = what edge
|
|
||||||
ABM_WINDOWPOSCHANGED* = 0x00000009
|
|
||||||
ABM_SETSTATE* = 0x0000000A
|
|
||||||
ABN_STATECHANGE* = 0x00000000 # these are put in the wparam of callback messages
|
|
||||||
ABN_POSCHANGED* = 0x00000001
|
|
||||||
ABN_FULLSCREENAPP* = 0x00000002
|
|
||||||
ABN_WINDOWARRANGE* = 0x00000003 # lParam == TRUE means hide
|
|
||||||
# flags for get state
|
|
||||||
ABS_AUTOHIDE* = 0x00000001
|
|
||||||
ABS_ALWAYSONTOP* = 0x00000002
|
|
||||||
ABE_LEFT* = 0
|
|
||||||
ABE_TOP* = 1
|
|
||||||
ABE_RIGHT* = 2
|
|
||||||
ABE_BOTTOM* = 3
|
|
||||||
|
|
||||||
type
|
|
||||||
AppBarData* {.final.} = object
|
|
||||||
cbSize*: DWORD
|
|
||||||
hWnd*: HWND
|
|
||||||
uCallbackMessage*: UINT
|
|
||||||
uEdge*: UINT
|
|
||||||
rc*: RECT
|
|
||||||
lParam*: LPARAM # message specific
|
|
||||||
|
|
||||||
TAPPBARDATA* = AppBarData
|
|
||||||
PAPPBARDATA* = ptr AppBarData
|
|
||||||
|
|
||||||
proc SHAppBarMessage*(dwMessage: DWORD, pData: APPBARDATA): UINT_PTR{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "SHAppBarMessage".}
|
|
||||||
#
|
|
||||||
# EndAppBar
|
|
||||||
#
|
|
||||||
proc DoEnvironmentSubstA*(szString: LPSTR, cchString: UINT): DWORD{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "DoEnvironmentSubstA".}
|
|
||||||
proc DoEnvironmentSubstW*(szString: LPWSTR, cchString: UINT): DWORD{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "DoEnvironmentSubstW".}
|
|
||||||
proc DoEnvironmentSubst*(szString: LPSTR, cchString: UINT): DWORD{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "DoEnvironmentSubstA".}
|
|
||||||
proc DoEnvironmentSubst*(szString: LPWSTR, cchString: UINT): DWORD{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "DoEnvironmentSubstW".}
|
|
||||||
#Macro
|
|
||||||
proc EIRESID*(x: int32): int32
|
|
||||||
proc ExtractIconExA*(lpszFile: LPCSTR, nIconIndex: int32, phiconLarge: pHICON,
|
|
||||||
phiconSmall: pHIcon, nIcons: UINT): UINT{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "ExtractIconExA".}
|
|
||||||
proc ExtractIconExW*(lpszFile: LPCWSTR, nIconIndex: int32, phiconLarge: pHICON,
|
|
||||||
phiconSmall: pHIcon, nIcons: UINT): UINT{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "ExtractIconExW".}
|
|
||||||
proc ExtractIconExA*(lpszFile: LPCSTR, nIconIndex: int32,
|
|
||||||
phiconLarge: var HICON, phiconSmall: var HIcon,
|
|
||||||
nIcons: UINT): UINT{.stdcall, dynlib: "shell32.dll",
|
|
||||||
importc: "ExtractIconExA".}
|
|
||||||
proc ExtractIconExW*(lpszFile: LPCWSTR, nIconIndex: int32,
|
|
||||||
phiconLarge: var HICON, phiconSmall: var HIcon,
|
|
||||||
nIcons: UINT): UINT{.stdcall, dynlib: "shell32.dll",
|
|
||||||
importc: "ExtractIconExW".}
|
|
||||||
proc ExtractIconEx*(lpszFile: LPCSTR, nIconIndex: int32, phiconLarge: pHICON,
|
|
||||||
phiconSmall: pHIcon, nIcons: UINT): UINT{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "ExtractIconExA".}
|
|
||||||
proc ExtractIconEx*(lpszFile: LPCWSTR, nIconIndex: int32, phiconLarge: pHICON,
|
|
||||||
phiconSmall: pHIcon, nIcons: UINT): UINT{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "ExtractIconExW".}
|
|
||||||
proc ExtractIconEx*(lpszFile: LPCSTR, nIconIndex: int32, phiconLarge: var HICON,
|
|
||||||
phiconSmall: var HIcon, nIcons: UINT): UINT{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "ExtractIconExA".}
|
|
||||||
proc ExtractIconEx*(lpszFile: LPCWSTR, nIconIndex: int32,
|
|
||||||
phiconLarge: var HICON, phiconSmall: var HIcon, nIcons: UINT): UINT{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "ExtractIconExW".}
|
|
||||||
#
|
|
||||||
# Shell File Operations
|
|
||||||
#
|
|
||||||
#ifndef FO_MOVE //these need to be kept in sync with the ones in shlobj.h}
|
|
||||||
const
|
|
||||||
FO_MOVE* = 0x00000001
|
|
||||||
FO_COPY* = 0x00000002
|
|
||||||
FO_DELETE* = 0x00000003
|
|
||||||
FO_RENAME* = 0x00000004
|
|
||||||
FOF_MULTIDESTFILES* = 0x00000001
|
|
||||||
FOF_CONFIRMMOUSE* = 0x00000002
|
|
||||||
FOF_SILENT* = 0x00000004 # don't create progress/report
|
|
||||||
FOF_RENAMEONCOLLISION* = 0x00000008
|
|
||||||
FOF_NOCONFIRMATION* = 0x00000010 # Don't prompt the user.
|
|
||||||
FOF_WANTMAPPINGHANDLE* = 0x00000020 # Fill in SHFILEOPSTRUCT.hNameMappings
|
|
||||||
FOF_ALLOWUNDO* = 0x00000040 # Must be freed using SHFreeNameMappings
|
|
||||||
FOF_FILESONLY* = 0x00000080 # on *.*, do only files
|
|
||||||
FOF_SIMPLEPROGRESS* = 0x00000100 # means don't show names of files
|
|
||||||
FOF_NOCONFIRMMKDIR* = 0x00000200 # don't confirm making any needed dirs
|
|
||||||
FOF_NOERRORUI* = 0x00000400 # don't put up error UI
|
|
||||||
FOF_NOCOPYSECURITYATTRIBS* = 0x00000800 # dont copy NT file Security Attributes
|
|
||||||
FOF_NORECURSION* = 0x00001000 # don't recurse into directories.
|
|
||||||
#if (_WIN32_IE >= 0x0500)
|
|
||||||
FOF_NO_CONNECTED_ELEMENTS* = 0x00002000 # don't operate on connected elements.
|
|
||||||
FOF_WANTNUKEWARNING* = 0x00004000 # during delete operation, warn if nuking instead of recycling (partially overrides FOF_NOCONFIRMATION)
|
|
||||||
#endif
|
|
||||||
#if (_WIN32_WINNT >= 0x0501)
|
|
||||||
FOF_NORECURSEREPARSE* = 0x00008000 # treat reparse points as objects, not containers
|
|
||||||
#endif
|
|
||||||
|
|
||||||
type
|
|
||||||
FILEOP_FLAGS* = int16
|
|
||||||
|
|
||||||
const
|
|
||||||
PO_DELETE* = 0x00000013 # printer is being deleted
|
|
||||||
PO_RENAME* = 0x00000014 # printer is being renamed
|
|
||||||
PO_PORTCHANGE* = 0x00000020 # port this printer connected to is being changed
|
|
||||||
# if this id is set, the strings received by
|
|
||||||
# the copyhook are a doubly-null terminated
|
|
||||||
# list of strings. The first is the printer
|
|
||||||
# name and the second is the printer port.
|
|
||||||
PO_REN_PORT* = 0x00000034 # PO_RENAME and PO_PORTCHANGE at same time.
|
|
||||||
# no POF_ flags currently defined
|
|
||||||
|
|
||||||
type
|
|
||||||
PRINTEROP_FLAGS* = int16 #endif}
|
|
||||||
# FO_MOVE
|
|
||||||
# implicit parameters are:
|
|
||||||
# if pFrom or pTo are unqualified names the current directories are
|
|
||||||
# taken from the global current drive/directory settings managed
|
|
||||||
# by Get/SetCurrentDrive/Directory
|
|
||||||
#
|
|
||||||
# the global confirmation settings
|
|
||||||
# only used if FOF_SIMPLEPROGRESS
|
|
||||||
|
|
||||||
type
|
|
||||||
SHFILEOPSTRUCTA* {.final.} = object
|
|
||||||
hwnd*: HWND
|
|
||||||
wFunc*: UINT
|
|
||||||
pFrom*: LPCSTR
|
|
||||||
pTo*: LPCSTR
|
|
||||||
fFlags*: FILEOP_FLAGS
|
|
||||||
fAnyOperationsAborted*: BOOL
|
|
||||||
hNameMappings*: LPVOID
|
|
||||||
lpszProgressTitle*: LPCSTR # only used if FOF_SIMPLEPROGRESS
|
|
||||||
|
|
||||||
TSHFILEOPSTRUCTA* = SHFILEOPSTRUCTA
|
|
||||||
LPSHFILEOPSTRUCTA* = ptr SHFILEOPSTRUCTA
|
|
||||||
SHFILEOPSTRUCTW* {.final.} = object
|
|
||||||
hwnd*: HWND
|
|
||||||
wFunc*: UINT
|
|
||||||
pFrom*: LPCWSTR
|
|
||||||
pTo*: LPCWSTR
|
|
||||||
fFlags*: FILEOP_FLAGS
|
|
||||||
fAnyOperationsAborted*: BOOL
|
|
||||||
hNameMappings*: LPVOID
|
|
||||||
lpszProgressTitle*: LPCWSTR
|
|
||||||
|
|
||||||
TSHFILEOPSTRUCTW* = SHFILEOPSTRUCTW
|
|
||||||
LPSHFILEOPSTRUCTW* = ptr SHFILEOPSTRUCTW
|
|
||||||
|
|
||||||
when defined(UNICODE):
|
|
||||||
type
|
|
||||||
SHFILEOPSTRUCT* = SHFILEOPSTRUCTW
|
|
||||||
TSHFILEOPSTRUCT* = SHFILEOPSTRUCTW
|
|
||||||
LPSHFILEOPSTRUCT* = LPSHFILEOPSTRUCTW
|
|
||||||
else:
|
|
||||||
type
|
|
||||||
SHFILEOPSTRUCT* = SHFILEOPSTRUCTA
|
|
||||||
TSHFILEOPSTRUCT* = SHFILEOPSTRUCTA
|
|
||||||
LPSHFILEOPSTRUCT* = LPSHFILEOPSTRUCTA
|
|
||||||
proc SHFileOperationA*(lpFileOp: LPSHFILEOPSTRUCTA): int32{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "SHFileOperationA".}
|
|
||||||
proc SHFileOperationW*(lpFileOp: LPSHFILEOPSTRUCTW): int32{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "SHFileOperationW".}
|
|
||||||
proc SHFileOperation*(lpFileOp: LPSHFILEOPSTRUCTA): int32{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "SHFileOperationA".}
|
|
||||||
proc SHFileOperation*(lpFileOp: LPSHFILEOPSTRUCTW): int32{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "SHFileOperationW".}
|
|
||||||
proc SHFreeNameMappings*(hNameMappings: THandle){.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "SHFreeNameMappings".}
|
|
||||||
type
|
|
||||||
SHNAMEMAPPINGA* {.final.} = object
|
|
||||||
pszOldPath*: LPSTR
|
|
||||||
pszNewPath*: LPSTR
|
|
||||||
cchOldPath*: int32
|
|
||||||
cchNewPath*: int32
|
|
||||||
|
|
||||||
TSHNAMEMAPPINGA* = SHNAMEMAPPINGA
|
|
||||||
LPSHNAMEMAPPINGA* = ptr SHNAMEMAPPINGA
|
|
||||||
SHNAMEMAPPINGW* {.final.} = object
|
|
||||||
pszOldPath*: LPWSTR
|
|
||||||
pszNewPath*: LPWSTR
|
|
||||||
cchOldPath*: int32
|
|
||||||
cchNewPath*: int32
|
|
||||||
|
|
||||||
TSHNAMEMAPPINGW* = SHNAMEMAPPINGW
|
|
||||||
LPSHNAMEMAPPINGW* = ptr SHNAMEMAPPINGW
|
|
||||||
|
|
||||||
when not(defined(UNICODE)):
|
|
||||||
type
|
|
||||||
SHNAMEMAPPING* = SHNAMEMAPPINGW
|
|
||||||
TSHNAMEMAPPING* = SHNAMEMAPPINGW
|
|
||||||
LPSHNAMEMAPPING* = LPSHNAMEMAPPINGW
|
|
||||||
else:
|
|
||||||
type
|
|
||||||
SHNAMEMAPPING* = SHNAMEMAPPINGA
|
|
||||||
TSHNAMEMAPPING* = SHNAMEMAPPINGA
|
|
||||||
LPSHNAMEMAPPING* = LPSHNAMEMAPPINGA
|
|
||||||
#
|
|
||||||
# End Shell File Operations
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# Begin ShellExecuteEx and family
|
|
||||||
#
|
|
||||||
# ShellExecute() and ShellExecuteEx() error codes
|
|
||||||
# regular WinExec() codes
|
|
||||||
|
|
||||||
const
|
|
||||||
SE_ERR_FNF* = 2 # file not found
|
|
||||||
SE_ERR_PNF* = 3 # path not found
|
|
||||||
SE_ERR_ACCESSDENIED* = 5 # access denied
|
|
||||||
SE_ERR_OOM* = 8 # out of memory
|
|
||||||
SE_ERR_DLLNOTFOUND* = 32 # endif WINVER >= 0x0400
|
|
||||||
# error values for ShellExecute() beyond the regular WinExec() codes
|
|
||||||
SE_ERR_SHARE* = 26
|
|
||||||
SE_ERR_ASSOCINCOMPLETE* = 27
|
|
||||||
SE_ERR_DDETIMEOUT* = 28
|
|
||||||
SE_ERR_DDEFAIL* = 29
|
|
||||||
SE_ERR_DDEBUSY* = 30
|
|
||||||
SE_ERR_NOASSOC* = 31 #if(WINVER >= 0x0400)}
|
|
||||||
# Note CLASSKEY overrides CLASSNAME
|
|
||||||
SEE_MASK_CLASSNAME* = 0x00000001
|
|
||||||
SEE_MASK_CLASSKEY* = 0x00000003 # Note INVOKEIDLIST overrides IDLIST
|
|
||||||
SEE_MASK_IDLIST* = 0x00000004
|
|
||||||
SEE_MASK_INVOKEIDLIST* = 0x0000000C
|
|
||||||
SEE_MASK_ICON* = 0x00000010
|
|
||||||
SEE_MASK_HOTKEY* = 0x00000020
|
|
||||||
SEE_MASK_NOCLOSEPROCESS* = 0x00000040
|
|
||||||
SEE_MASK_CONNECTNETDRV* = 0x00000080
|
|
||||||
SEE_MASK_FLAG_DDEWAIT* = 0x00000100
|
|
||||||
SEE_MASK_DOENVSUBST* = 0x00000200
|
|
||||||
SEE_MASK_FLAG_NO_UI* = 0x00000400
|
|
||||||
SEE_MASK_UNICODE* = 0x00004000
|
|
||||||
SEE_MASK_NO_CONSOLE* = 0x00008000
|
|
||||||
SEE_MASK_ASYNCOK* = 0x00100000
|
|
||||||
SEE_MASK_HMONITOR* = 0x00200000 #if (_WIN32_IE >= 0x0500)
|
|
||||||
SEE_MASK_NOQUERYCLASSSTORE* = 0x01000000
|
|
||||||
SEE_MASK_WAITFORINPUTIDLE* = 0x02000000 #endif (_WIN32_IE >= 0x500)
|
|
||||||
#if (_WIN32_IE >= 0x0560)
|
|
||||||
SEE_MASK_FLAG_LOG_USAGE* = 0x04000000 #endif
|
|
||||||
# (_WIN32_IE >= 0x560)
|
|
||||||
|
|
||||||
type
|
|
||||||
SHELLEXECUTEINFOA* {.final.} = object
|
|
||||||
cbSize*: DWORD
|
|
||||||
fMask*: ULONG
|
|
||||||
hwnd*: HWND
|
|
||||||
lpVerb*: LPCSTR
|
|
||||||
lpFile*: LPCSTR
|
|
||||||
lpParameters*: LPCSTR
|
|
||||||
lpDirectory*: LPCSTR
|
|
||||||
nShow*: int32
|
|
||||||
hInstApp*: HINST
|
|
||||||
lpIDList*: LPVOID
|
|
||||||
lpClass*: LPCSTR
|
|
||||||
hkeyClass*: HKEY
|
|
||||||
dwHotKey*: DWORD
|
|
||||||
hMonitor*: HANDLE # also: hIcon
|
|
||||||
hProcess*: HANDLE
|
|
||||||
|
|
||||||
TSHELLEXECUTEINFOA* = SHELLEXECUTEINFOA
|
|
||||||
LPSHELLEXECUTEINFOA* = ptr SHELLEXECUTEINFOA
|
|
||||||
SHELLEXECUTEINFOW* {.final.} = object
|
|
||||||
cbSize*: DWORD
|
|
||||||
fMask*: ULONG
|
|
||||||
hwnd*: HWND
|
|
||||||
lpVerb*: lpcwstr
|
|
||||||
lpFile*: lpcwstr
|
|
||||||
lpParameters*: lpcwstr
|
|
||||||
lpDirectory*: lpcwstr
|
|
||||||
nShow*: int32
|
|
||||||
hInstApp*: HINST
|
|
||||||
lpIDList*: LPVOID
|
|
||||||
lpClass*: LPCWSTR
|
|
||||||
hkeyClass*: HKEY
|
|
||||||
dwHotKey*: DWORD
|
|
||||||
hMonitor*: HANDLE # also: hIcon
|
|
||||||
hProcess*: HANDLE
|
|
||||||
|
|
||||||
TSHELLEXECUTEINFOW* = SHELLEXECUTEINFOW
|
|
||||||
LPSHELLEXECUTEINFOW* = ptr SHELLEXECUTEINFOW
|
|
||||||
|
|
||||||
when defined(UNICODE):
|
|
||||||
type
|
|
||||||
SHELLEXECUTEINFO* = SHELLEXECUTEINFOW
|
|
||||||
TSHELLEXECUTEINFO* = SHELLEXECUTEINFOW
|
|
||||||
LPSHELLEXECUTEINFO* = LPSHELLEXECUTEINFOW
|
|
||||||
else:
|
|
||||||
type
|
|
||||||
SHELLEXECUTEINFO* = SHELLEXECUTEINFOA
|
|
||||||
TSHELLEXECUTEINFO* = SHELLEXECUTEINFOA
|
|
||||||
LPSHELLEXECUTEINFO* = LPSHELLEXECUTEINFOA
|
|
||||||
proc ShellExecuteExA*(lpExecInfo: LPSHELLEXECUTEINFOA): Bool{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "ShellExecuteExA".}
|
|
||||||
proc ShellExecuteExW*(lpExecInfo: LPSHELLEXECUTEINFOW): Bool{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "ShellExecuteExW".}
|
|
||||||
proc ShellExecuteEx*(lpExecInfo: LPSHELLEXECUTEINFOA): Bool{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "ShellExecuteExA".}
|
|
||||||
proc ShellExecuteEx*(lpExecInfo: LPSHELLEXECUTEINFOW): Bool{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "ShellExecuteExW".}
|
|
||||||
proc WinExecErrorA*(HWND: hwnd, error: int32, lpstrFileName: LPCSTR,
|
|
||||||
lpstrTitle: LPCSTR){.stdcall, dynlib: "shell32.dll",
|
|
||||||
importc: "WinExecErrorA".}
|
|
||||||
proc WinExecErrorW*(HWND: hwnd, error: int32, lpstrFileName: LPCWSTR,
|
|
||||||
lpstrTitle: LPCWSTR){.stdcall, dynlib: "shell32.dll",
|
|
||||||
importc: "WinExecErrorW".}
|
|
||||||
proc WinExecError*(HWND: hwnd, error: int32, lpstrFileName: LPCSTR,
|
|
||||||
lpstrTitle: LPCSTR){.stdcall, dynlib: "shell32.dll",
|
|
||||||
importc: "WinExecErrorA".}
|
|
||||||
proc WinExecError*(HWND: hwnd, error: int32, lpstrFileName: LPCWSTR,
|
|
||||||
lpstrTitle: LPCWSTR){.stdcall, dynlib: "shell32.dll",
|
|
||||||
importc: "WinExecErrorW".}
|
|
||||||
type
|
|
||||||
SHCREATEPROCESSINFOW* {.final.} = object
|
|
||||||
cbSize*: DWORD
|
|
||||||
fMask*: ULONG
|
|
||||||
hwnd*: HWND
|
|
||||||
pszFile*: LPCWSTR
|
|
||||||
pszParameters*: LPCWSTR
|
|
||||||
pszCurrentDirectory*: LPCWSTR
|
|
||||||
hUserToken*: HANDLE
|
|
||||||
lpProcessAttributes*: LPSECURITY_ATTRIBUTES
|
|
||||||
lpThreadAttributes*: LPSECURITY_ATTRIBUTES
|
|
||||||
bInheritHandles*: BOOL
|
|
||||||
dwCreationFlags*: DWORD
|
|
||||||
lpStartupInfo*: LPSTARTUPINFOW
|
|
||||||
lpProcessInformation*: LPPROCESS_INFORMATION
|
|
||||||
|
|
||||||
TSHCREATEPROCESSINFOW* = SHCREATEPROCESSINFOW
|
|
||||||
PSHCREATEPROCESSINFOW* = ptr SHCREATEPROCESSINFOW
|
|
||||||
|
|
||||||
proc SHCreateProcessAsUserW*(pscpi: PSHCREATEPROCESSINFOW): Bool{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "SHCreateProcessAsUserW".}
|
|
||||||
#
|
|
||||||
# End ShellExecuteEx and family }
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# RecycleBin
|
|
||||||
#
|
|
||||||
# struct for query recycle bin info
|
|
||||||
type
|
|
||||||
SHQUERYRBINFO* {.final.} = object
|
|
||||||
cbSize*: DWORD
|
|
||||||
i64Size*: int64
|
|
||||||
i64NumItems*: int64
|
|
||||||
|
|
||||||
TSHQUERYRBINFO* = SHQUERYRBINFO
|
|
||||||
LPSHQUERYRBINFO* = ptr SHQUERYRBINFO # flags for SHEmptyRecycleBin
|
|
||||||
|
|
||||||
const
|
|
||||||
SHERB_NOCONFIRMATION* = 0x00000001
|
|
||||||
SHERB_NOPROGRESSUI* = 0x00000002
|
|
||||||
SHERB_NOSOUND* = 0x00000004
|
|
||||||
|
|
||||||
proc SHQueryRecycleBinA*(pszRootPath: LPCSTR, pSHQueryRBInfo: LPSHQUERYRBINFO): HRESULT{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "SHQueryRecycleBinA".}
|
|
||||||
proc SHQueryRecycleBinW*(pszRootPath: LPCWSTR, pSHQueryRBInfo: LPSHQUERYRBINFO): HRESULT{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "SHQueryRecycleBinW".}
|
|
||||||
proc SHQueryRecycleBin*(pszRootPath: LPCSTR, pSHQueryRBInfo: LPSHQUERYRBINFO): HRESULT{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "SHQueryRecycleBinA".}
|
|
||||||
proc SHQueryRecycleBin*(pszRootPath: LPCWSTR, pSHQueryRBInfo: LPSHQUERYRBINFO): HRESULT{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "SHQueryRecycleBinW".}
|
|
||||||
proc SHEmptyRecycleBinA*(hwnd: HWND, pszRootPath: LPCSTR, dwFlags: DWORD): HRESULT{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "SHEmptyRecycleBinA".}
|
|
||||||
proc SHEmptyRecycleBinW*(hwnd: HWND, pszRootPath: LPCWSTR, dwFlags: DWORD): HRESULT{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "SHEmptyRecycleBinW".}
|
|
||||||
proc SHEmptyRecycleBin*(hwnd: HWND, pszRootPath: LPCSTR, dwFlags: DWORD): HRESULT{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "SHEmptyRecycleBinA".}
|
|
||||||
proc SHEmptyRecycleBin*(hwnd: HWND, pszRootPath: LPCWSTR, dwFlags: DWORD): HRESULT{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "SHEmptyRecycleBinW".}
|
|
||||||
#
|
|
||||||
# end of RecycleBin
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# Tray notification definitions
|
|
||||||
#
|
|
||||||
type
|
|
||||||
NOTIFYICONDATAA* {.final.} = object
|
|
||||||
cbSize*: DWORD
|
|
||||||
hWnd*: HWND
|
|
||||||
uID*: UINT
|
|
||||||
uFlags*: UINT
|
|
||||||
uCallbackMessage*: UINT
|
|
||||||
hIcon*: HICON
|
|
||||||
szTip*: array[0..127, CHAR]
|
|
||||||
dwState*: DWORD
|
|
||||||
dwStateMask*: DWORD
|
|
||||||
szInfo*: array[0..255, CHAR]
|
|
||||||
uTimeout*: UINT # also: uVersion
|
|
||||||
szInfoTitle*: array[0..63, CHAR]
|
|
||||||
dwInfoFlags*: DWORD
|
|
||||||
guidItem*: TGUID
|
|
||||||
|
|
||||||
TNOTIFYICONDATAA* = NOTIFYICONDATAA
|
|
||||||
PNOTIFYICONDATAA* = ptr NOTIFYICONDATAA
|
|
||||||
NOTIFYICONDATAW* {.final.} = object
|
|
||||||
cbSize*: DWORD
|
|
||||||
hWnd*: HWND
|
|
||||||
uID*: UINT
|
|
||||||
uFlags*: UINT
|
|
||||||
uCallbackMessage*: UINT
|
|
||||||
hIcon*: HICON
|
|
||||||
szTip*: array[0..127, WCHAR]
|
|
||||||
dwState*: DWORD
|
|
||||||
dwStateMask*: DWORD
|
|
||||||
szInfo*: array[0..255, WCHAR]
|
|
||||||
uTimeout*: UINT # also uVersion : UINT
|
|
||||||
szInfoTitle*: array[0..63, CHAR]
|
|
||||||
dwInfoFlags*: DWORD
|
|
||||||
guidItem*: TGUID
|
|
||||||
|
|
||||||
TNOTIFYICONDATAW* = NOTIFYICONDATAW
|
|
||||||
PNOTIFYICONDATAW* = ptr NOTIFYICONDATAW
|
|
||||||
|
|
||||||
when defined(UNICODE):
|
|
||||||
type
|
|
||||||
NOTIFYICONDATA* = NOTIFYICONDATAW
|
|
||||||
TNOTIFYICONDATA* = NOTIFYICONDATAW
|
|
||||||
PNOTIFYICONDATA* = PNOTIFYICONDATAW
|
|
||||||
else:
|
|
||||||
type
|
|
||||||
NOTIFYICONDATA* = NOTIFYICONDATAA
|
|
||||||
TNOTIFYICONDATA* = NOTIFYICONDATAA
|
|
||||||
PNOTIFYICONDATA* = PNOTIFYICONDATAA
|
|
||||||
const
|
|
||||||
NIN_SELECT* = WM_USER + 0
|
|
||||||
NINF_KEY* = 0x00000001
|
|
||||||
NIN_KEYSELECT* = NIN_SELECT or NINF_KEY
|
|
||||||
NIN_BALLOONSHOW* = WM_USER + 2
|
|
||||||
NIN_BALLOONHIDE* = WM_USER + 3
|
|
||||||
NIN_BALLOONTIMEOUT* = WM_USER + 4
|
|
||||||
NIN_BALLOONUSERCLICK* = WM_USER + 5
|
|
||||||
NIM_ADD* = 0x00000000
|
|
||||||
NIM_MODIFY* = 0x00000001
|
|
||||||
NIM_DELETE* = 0x00000002
|
|
||||||
NIM_SETFOCUS* = 0x00000003
|
|
||||||
NIM_SETVERSION* = 0x00000004
|
|
||||||
NOTIFYICON_VERSION* = 3
|
|
||||||
NIF_MESSAGE* = 0x00000001
|
|
||||||
NIF_ICON* = 0x00000002
|
|
||||||
NIF_TIP* = 0x00000004
|
|
||||||
NIF_STATE* = 0x00000008
|
|
||||||
NIF_INFO* = 0x00000010
|
|
||||||
NIF_GUID* = 0x00000020
|
|
||||||
NIS_HIDDEN* = 0x00000001
|
|
||||||
NIS_SHAREDICON* = 0x00000002 # says this is the source of a shared icon
|
|
||||||
# Notify Icon Infotip flags
|
|
||||||
NIIF_NONE* = 0x00000000 # icon flags are mutually exclusive
|
|
||||||
# and take only the lowest 2 bits
|
|
||||||
NIIF_INFO* = 0x00000001
|
|
||||||
NIIF_WARNING* = 0x00000002
|
|
||||||
NIIF_ERROR* = 0x00000003
|
|
||||||
NIIF_ICON_MASK* = 0x0000000F
|
|
||||||
NIIF_NOSOUND* = 0x00000010
|
|
||||||
|
|
||||||
proc Shell_NotifyIconA*(dwMessage: Dword, lpData: PNOTIFYICONDATAA): Bool{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "Shell_NotifyIconA".}
|
|
||||||
proc Shell_NotifyIconW*(dwMessage: Dword, lpData: PNOTIFYICONDATAW): Bool{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "Shell_NotifyIconW".}
|
|
||||||
proc Shell_NotifyIcon*(dwMessage: Dword, lpData: PNOTIFYICONDATAA): Bool{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "Shell_NotifyIconA".}
|
|
||||||
proc Shell_NotifyIcon*(dwMessage: Dword, lpData: PNOTIFYICONDATAW): Bool{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "Shell_NotifyIconW".}
|
|
||||||
#
|
|
||||||
# The SHGetFileInfo API provides an easy way to get attributes
|
|
||||||
# for a file given a pathname.
|
|
||||||
#
|
|
||||||
# PARAMETERS
|
|
||||||
#
|
|
||||||
# pszPath file name to get info about
|
|
||||||
# dwFileAttributes file attribs, only used with SHGFI_USEFILEATTRIBUTES
|
|
||||||
# psfi place to return file info
|
|
||||||
# cbFileInfo size of structure
|
|
||||||
# uFlags flags
|
|
||||||
#
|
|
||||||
# RETURN
|
|
||||||
# TRUE if things worked
|
|
||||||
#
|
|
||||||
# out: icon
|
|
||||||
# out: icon index
|
|
||||||
# out: SFGAO_ flags
|
|
||||||
# out: display name (or path)
|
|
||||||
# out: type name
|
|
||||||
type
|
|
||||||
SHFILEINFOA* {.final.} = object
|
|
||||||
hIcon*: HICON # out: icon
|
|
||||||
iIcon*: int32 # out: icon index
|
|
||||||
dwAttributes*: DWORD # out: SFGAO_ flags
|
|
||||||
szDisplayName*: array[0..(MAX_PATH) - 1, CHAR] # out: display name (or path)
|
|
||||||
szTypeName*: array[0..79, CHAR] # out: type name
|
|
||||||
|
|
||||||
TSHFILEINFOA* = SHFILEINFOA
|
|
||||||
pSHFILEINFOA* = ptr SHFILEINFOA
|
|
||||||
SHFILEINFOW* {.final.} = object
|
|
||||||
hIcon*: HICON # out: icon
|
|
||||||
iIcon*: int32 # out: icon index
|
|
||||||
dwAttributes*: DWORD # out: SFGAO_ flags
|
|
||||||
szDisplayName*: array[0..(MAX_PATH) - 1, WCHAR] # out: display name (or path)
|
|
||||||
szTypeName*: array[0..79, WCHAR] # out: type name
|
|
||||||
|
|
||||||
TSHFILEINFOW* = SHFILEINFOW
|
|
||||||
pSHFILEINFOW* = ptr SHFILEINFOW
|
|
||||||
|
|
||||||
when defined(UNICODE):
|
|
||||||
type
|
|
||||||
SHFILEINFO* = SHFILEINFOW
|
|
||||||
TSHFILEINFO* = SHFILEINFOW
|
|
||||||
pFILEINFO* = SHFILEINFOW
|
|
||||||
else:
|
|
||||||
type
|
|
||||||
SHFILEINFO* = SHFILEINFOA
|
|
||||||
TSHFILEINFO* = SHFILEINFOA
|
|
||||||
pFILEINFO* = SHFILEINFOA
|
|
||||||
# NOTE: This is also in shlwapi.h. Please keep in synch.
|
|
||||||
|
|
||||||
const
|
|
||||||
SHGFI_ICON* = 0x00000100 # get Icon
|
|
||||||
SHGFI_DISPLAYNAME* = 0x00000200 # get display name
|
|
||||||
SHGFI_TYPENAME* = 0x00000400 # get type name
|
|
||||||
SHGFI_ATTRIBUTES* = 0x00000800 # get attributes
|
|
||||||
SHGFI_ICONLOCATION* = 0x00001000 # get icon location
|
|
||||||
SHGFI_EXETYPE* = 0x00002000 # return exe type
|
|
||||||
SHGFI_SYSICONINDEX* = 0x00004000 # get system icon index
|
|
||||||
SHGFI_LINKOVERLAY* = 0x00008000 # put a link overlay on icon
|
|
||||||
SHGFI_SELECTED* = 0x00010000 # show icon in selected state
|
|
||||||
SHGFI_ATTR_SPECIFIED* = 0x00020000 # get only specified attributes
|
|
||||||
SHGFI_LARGEICON* = 0x00000000 # get large icon
|
|
||||||
SHGFI_SMALLICON* = 0x00000001 # get small icon
|
|
||||||
SHGFI_OPENICON* = 0x00000002 # get open icon
|
|
||||||
SHGFI_SHELLICONSIZE* = 0x00000004 # get shell size icon
|
|
||||||
SHGFI_PIDL* = 0x00000008 # pszPath is a pidl
|
|
||||||
SHGFI_USEFILEATTRIBUTES* = 0x00000010 # use passed dwFileAttribute
|
|
||||||
SHGFI_ADDOVERLAYS* = 0x00000020 # apply the appropriate overlays
|
|
||||||
SHGFI_OVERLAYINDEX* = 0x00000040 # Get the index of the overlay
|
|
||||||
# in the upper 8 bits of the iIcon
|
|
||||||
|
|
||||||
proc SHGetFileInfoA*(pszPath: LPCSTR, dwFileAttributes: DWORD,
|
|
||||||
psfi: pSHFILEINFOA, cbFileInfo, UFlags: UINT): DWORD{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "SHGetFileInfoA".}
|
|
||||||
proc SHGetFileInfoW*(pszPath: LPCWSTR, dwFileAttributes: DWORD,
|
|
||||||
psfi: pSHFILEINFOW, cbFileInfo, UFlags: UINT): DWORD{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "SHGetFileInfoW".}
|
|
||||||
proc SHGetFileInfo*(pszPath: LPCSTR, dwFileAttributes: DWORD,
|
|
||||||
psfi: pSHFILEINFOA, cbFileInfo, UFlags: UINT): DWORD{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "SHGetFileInfoA".}
|
|
||||||
proc SHGetFileInfoA*(pszPath: LPCSTR, dwFileAttributes: DWORD,
|
|
||||||
psfi: var TSHFILEINFOA, cbFileInfo, UFlags: UINT): DWORD{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "SHGetFileInfoA".}
|
|
||||||
proc SHGetFileInfoW*(pszPath: LPCWSTR, dwFileAttributes: DWORD,
|
|
||||||
psfi: var TSHFILEINFOW, cbFileInfo, UFlags: UINT): DWORD{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "SHGetFileInfoW".}
|
|
||||||
proc SHGetFileInfo*(pszPath: LPCSTR, dwFileAttributes: DWORD,
|
|
||||||
psfi: var TSHFILEINFOA, cbFileInfo, UFlags: UINT): DWORD{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "SHGetFileInfoA".}
|
|
||||||
proc SHGetFileInfo*(pszPath: LPCWSTR, dwFileAttributes: DWORD,
|
|
||||||
psfi: var TSHFILEINFOW, cbFileInfo, UFlags: UINT): DWORD{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "SHGetFileInfoW".}
|
|
||||||
proc SHGetDiskFreeSpaceExA*(pszDirectoryName: LPCSTR,
|
|
||||||
pulFreeBytesAvailableToCaller: pULARGE_INTEGER,
|
|
||||||
pulTotalNumberOfBytes: pULARGE_INTEGER,
|
|
||||||
pulTotalNumberOfFreeBytes: pULARGE_INTEGER): Bool{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "SHGetDiskFreeSpaceExA".}
|
|
||||||
proc SHGetDiskFreeSpaceExW*(pszDirectoryName: LPCWSTR,
|
|
||||||
pulFreeBytesAvailableToCaller: pULARGE_INTEGER,
|
|
||||||
pulTotalNumberOfBytes: pULARGE_INTEGER,
|
|
||||||
pulTotalNumberOfFreeBytes: pULARGE_INTEGER): Bool{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "SHGetDiskFreeSpaceExW".}
|
|
||||||
proc SHGetDiskFreeSpaceEx*(pszDirectoryName: LPCSTR,
|
|
||||||
pulFreeBytesAvailableToCaller: pULARGE_INTEGER,
|
|
||||||
pulTotalNumberOfBytes: pULARGE_INTEGER,
|
|
||||||
pulTotalNumberOfFreeBytes: pULARGE_INTEGER): Bool{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "SHGetDiskFreeSpaceExA".}
|
|
||||||
proc SHGetDiskFreeSpace*(pszDirectoryName: LPCSTR,
|
|
||||||
pulFreeBytesAvailableToCaller: pULARGE_INTEGER,
|
|
||||||
pulTotalNumberOfBytes: pULARGE_INTEGER,
|
|
||||||
pulTotalNumberOfFreeBytes: pULARGE_INTEGER): Bool{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "SHGetDiskFreeSpaceExA".}
|
|
||||||
proc SHGetDiskFreeSpaceEx*(pszDirectoryName: LPCWSTR,
|
|
||||||
pulFreeBytesAvailableToCaller: pULARGE_INTEGER,
|
|
||||||
pulTotalNumberOfBytes: pULARGE_INTEGER,
|
|
||||||
pulTotalNumberOfFreeBytes: pULARGE_INTEGER): Bool{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "SHGetDiskFreeSpaceExW".}
|
|
||||||
proc SHGetDiskFreeSpace*(pszDirectoryName: LPCWSTR,
|
|
||||||
pulFreeBytesAvailableToCaller: pULARGE_INTEGER,
|
|
||||||
pulTotalNumberOfBytes: pULARGE_INTEGER,
|
|
||||||
pulTotalNumberOfFreeBytes: pULARGE_INTEGER): Bool{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "SHGetDiskFreeSpaceExW".}
|
|
||||||
proc SHGetNewLinkInfoA*(pszLinkTo: LPCSTR, pszDir: LPCSTR, pszName: LPSTR,
|
|
||||||
pfMustCopy: pBool, uFlags: UINT): Bool{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "SHGetNewLinkInfoA".}
|
|
||||||
proc SHGetNewLinkInfoW*(pszLinkTo: LPCWSTR, pszDir: LPCWSTR, pszName: LPWSTR,
|
|
||||||
pfMustCopy: pBool, uFlags: UINT): Bool{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "SHGetNewLinkInfoW".}
|
|
||||||
proc SHGetNewLinkInfo*(pszLinkTo: LPCSTR, pszDir: LPCSTR, pszName: LPSTR,
|
|
||||||
pfMustCopy: pBool, uFlags: UINT): Bool{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "SHGetNewLinkInfoA".}
|
|
||||||
proc SHGetNewLinkInfo*(pszLinkTo: LPCWSTR, pszDir: LPCWSTR, pszName: LPWSTR,
|
|
||||||
pfMustCopy: pBool, uFlags: UINT): Bool{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "SHGetNewLinkInfoW".}
|
|
||||||
const
|
|
||||||
SHGNLI_PIDL* = 0x00000001 # pszLinkTo is a pidl
|
|
||||||
SHGNLI_PREFIXNAME* = 0x00000002 # Make name "Shortcut to xxx"
|
|
||||||
SHGNLI_NOUNIQUE* = 0x00000004 # don't do the unique name generation
|
|
||||||
SHGNLI_NOLNK* = 0x00000008 # don't add ".lnk" extension
|
|
||||||
PRINTACTION_OPEN* = 0
|
|
||||||
PRINTACTION_PROPERTIES* = 1
|
|
||||||
PRINTACTION_NETINSTALL* = 2
|
|
||||||
PRINTACTION_NETINSTALLLINK* = 3
|
|
||||||
PRINTACTION_TESTPAGE* = 4
|
|
||||||
PRINTACTION_OPENNETPRN* = 5
|
|
||||||
PRINTACTION_DOCUMENTDEFAULTS* = 6
|
|
||||||
PRINTACTION_SERVERPROPERTIES* = 7
|
|
||||||
|
|
||||||
proc SHInvokePrinterCommandA*(HWND: hwnd, uAction: UINT, lpBuf1: LPCSTR,
|
|
||||||
lpBuf2: LPCSTR, fModal: Bool): Bool{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "SHInvokePrinterCommandA".}
|
|
||||||
proc SHInvokePrinterCommandW*(HWND: hwnd, uAction: UINT, lpBuf1: LPCWSTR,
|
|
||||||
lpBuf2: LPCWSTR, fModal: Bool): Bool{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "SHInvokePrinterCommandW".}
|
|
||||||
proc SHInvokePrinterCommand*(HWND: hwnd, uAction: UINT, lpBuf1: LPCSTR,
|
|
||||||
lpBuf2: LPCSTR, fModal: Bool): Bool{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "SHInvokePrinterCommandA".}
|
|
||||||
proc SHInvokePrinterCommand*(HWND: hwnd, uAction: UINT, lpBuf1: LPCWSTR,
|
|
||||||
lpBuf2: LPCWSTR, fModal: Bool): Bool{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "SHInvokePrinterCommandW".}
|
|
||||||
proc SHLoadNonloadedIconOverlayIdentifiers*(): HResult{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "SHInvokePrinterCommandW".}
|
|
||||||
proc SHIsFileAvailableOffline*(pwszPath: LPCWSTR, pdwStatus: LPDWORD): HRESULT{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "SHIsFileAvailableOffline".}
|
|
||||||
const
|
|
||||||
OFFLINE_STATUS_LOCAL* = 0x00000001 # If open, it's open locally
|
|
||||||
OFFLINE_STATUS_REMOTE* = 0x00000002 # If open, it's open remotely
|
|
||||||
OFFLINE_STATUS_INCOMPLETE* = 0x00000004 # The local copy is currently incomplete.
|
|
||||||
# The file will not be available offline
|
|
||||||
# until it has been synchronized.
|
|
||||||
# sets the specified path to use the string resource
|
|
||||||
# as the UI instead of the file system name
|
|
||||||
|
|
||||||
proc SHSetLocalizedName*(pszPath: LPWSTR, pszResModule: LPCWSTR, idsRes: int32): HRESULT{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "SHSetLocalizedName".}
|
|
||||||
proc SHEnumerateUnreadMailAccountsA*(hKeyUser: HKEY, dwIndex: DWORD,
|
|
||||||
pszMailAddress: LPSTR,
|
|
||||||
cchMailAddress: int32): HRESULT{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "SHEnumerateUnreadMailAccountsA".}
|
|
||||||
proc SHEnumerateUnreadMailAccountsW*(hKeyUser: HKEY, dwIndex: DWORD,
|
|
||||||
pszMailAddress: LPWSTR,
|
|
||||||
cchMailAddress: int32): HRESULT{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "SHEnumerateUnreadMailAccountsW".}
|
|
||||||
proc SHEnumerateUnreadMailAccounts*(hKeyUser: HKEY, dwIndex: DWORD,
|
|
||||||
pszMailAddress: LPWSTR,
|
|
||||||
cchMailAddress: int32): HRESULT{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "SHEnumerateUnreadMailAccountsW".}
|
|
||||||
proc SHGetUnreadMailCountA*(hKeyUser: HKEY, pszMailAddress: LPCSTR,
|
|
||||||
pdwCount: PDWORD, pFileTime: PFILETIME,
|
|
||||||
pszShellExecuteCommand: LPSTR,
|
|
||||||
cchShellExecuteCommand: int32): HRESULT{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "SHGetUnreadMailCountA".}
|
|
||||||
proc SHGetUnreadMailCountW*(hKeyUser: HKEY, pszMailAddress: LPCWSTR,
|
|
||||||
pdwCount: PDWORD, pFileTime: PFILETIME,
|
|
||||||
pszShellExecuteCommand: LPWSTR,
|
|
||||||
cchShellExecuteCommand: int32): HRESULT{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "SHGetUnreadMailCountW".}
|
|
||||||
proc SHGetUnreadMailCount*(hKeyUser: HKEY, pszMailAddress: LPCSTR,
|
|
||||||
pdwCount: PDWORD, pFileTime: PFILETIME,
|
|
||||||
pszShellExecuteCommand: LPSTR,
|
|
||||||
cchShellExecuteCommand: int32): HRESULT{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "SHGetUnreadMailCountA".}
|
|
||||||
proc SHGetUnreadMailCount*(hKeyUser: HKEY, pszMailAddress: LPCWSTR,
|
|
||||||
pdwCount: PDWORD, pFileTime: PFILETIME,
|
|
||||||
pszShellExecuteCommand: LPWSTR,
|
|
||||||
cchShellExecuteCommand: int32): HRESULT{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "SHGetUnreadMailCountW".}
|
|
||||||
proc SHSetUnreadMailCountA*(pszMailAddress: LPCSTR, dwCount: DWORD,
|
|
||||||
pszShellExecuteCommand: LPCSTR): HRESULT{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "SHSetUnreadMailCountA".}
|
|
||||||
proc SHSetUnreadMailCountW*(pszMailAddress: LPCWSTR, dwCount: DWORD,
|
|
||||||
pszShellExecuteCommand: LPCWSTR): HRESULT{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "SHSetUnreadMailCountW".}
|
|
||||||
proc SHSetUnreadMailCount*(pszMailAddress: LPCSTR, dwCount: DWORD,
|
|
||||||
pszShellExecuteCommand: LPCSTR): HRESULT{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "SHSetUnreadMailCountA".}
|
|
||||||
proc SHSetUnreadMailCount*(pszMailAddress: LPCWSTR, dwCount: DWORD,
|
|
||||||
pszShellExecuteCommand: LPCWSTR): HRESULT{.stdcall,
|
|
||||||
dynlib: "shell32.dll", importc: "SHSetUnreadMailCountW".}
|
|
||||||
proc SHGetImageList*(iImageList: int32, riid: TIID, ppvObj: ptr pointer): HRESULT{.
|
|
||||||
stdcall, dynlib: "shell32.dll", importc: "SHGetImageList".}
|
|
||||||
const
|
|
||||||
SHIL_LARGE* = 0 # normally 32x32
|
|
||||||
SHIL_SMALL* = 1 # normally 16x16
|
|
||||||
SHIL_EXTRALARGE* = 2
|
|
||||||
SHIL_SYSSMALL* = 3 # like SHIL_SMALL, but tracks system small icon metric correctly
|
|
||||||
SHIL_LAST* = SHIL_SYSSMALL
|
|
||||||
|
|
||||||
# implementation
|
|
||||||
|
|
||||||
proc EIRESID(x: int32): int32 =
|
|
||||||
result = -x
|
|
||||||
|
|
@ -1,93 +0,0 @@
|
||||||
#
|
|
||||||
#
|
|
||||||
# Nimrod's Runtime Library
|
|
||||||
# (c) Copyright 2006 Andreas Rumpf
|
|
||||||
#
|
|
||||||
# See the file "copying.txt", included in this
|
|
||||||
# distribution, for details about the copyright.
|
|
||||||
#
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------
|
|
||||||
# shfolder.dll is distributed standard with IE5.5, so it should ship
|
|
||||||
# with 2000/XP or higher but is likely to be installed on NT/95/98 or
|
|
||||||
# ME as well. It works on all these systems.
|
|
||||||
#
|
|
||||||
# The info found here is also in the registry:
|
|
||||||
# HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\
|
|
||||||
# HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\
|
|
||||||
#
|
|
||||||
# Note that not all CSIDL_* constants are supported by shlfolder.dll,
|
|
||||||
# they should be supported by the shell32.dll, though again not on all
|
|
||||||
# systems.
|
|
||||||
# ---------------------------------------------------------------------
|
|
||||||
|
|
||||||
{.deadCodeElim: on.}
|
|
||||||
|
|
||||||
import
|
|
||||||
windows
|
|
||||||
|
|
||||||
const
|
|
||||||
LibName* = "SHFolder.dll"
|
|
||||||
|
|
||||||
const
|
|
||||||
CSIDL_PROGRAMS* = 0x00000002 # %SYSTEMDRIVE%\Program Files
|
|
||||||
CSIDL_PERSONAL* = 0x00000005 # %USERPROFILE%\My Documents
|
|
||||||
CSIDL_FAVORITES* = 0x00000006 # %USERPROFILE%\Favorites
|
|
||||||
CSIDL_STARTUP* = 0x00000007 # %USERPROFILE%\Start menu\Programs\Startup
|
|
||||||
CSIDL_RECENT* = 0x00000008 # %USERPROFILE%\Recent
|
|
||||||
CSIDL_SENDTO* = 0x00000009 # %USERPROFILE%\Sendto
|
|
||||||
CSIDL_STARTMENU* = 0x0000000B # %USERPROFILE%\Start menu
|
|
||||||
CSIDL_MYMUSIC* = 0x0000000D # %USERPROFILE%\Documents\My Music
|
|
||||||
CSIDL_MYVIDEO* = 0x0000000E # %USERPROFILE%\Documents\My Videos
|
|
||||||
CSIDL_DESKTOPDIRECTORY* = 0x00000010 # %USERPROFILE%\Desktop
|
|
||||||
CSIDL_NETHOOD* = 0x00000013 # %USERPROFILE%\NetHood
|
|
||||||
CSIDL_TEMPLATES* = 0x00000015 # %USERPROFILE%\Templates
|
|
||||||
CSIDL_COMMON_STARTMENU* = 0x00000016 # %PROFILEPATH%\All users\Start menu
|
|
||||||
CSIDL_COMMON_PROGRAMS* = 0x00000017 # %PROFILEPATH%\All users\Start menu\Programs
|
|
||||||
CSIDL_COMMON_STARTUP* = 0x00000018 # %PROFILEPATH%\All users\Start menu\Programs\Startup
|
|
||||||
CSIDL_COMMON_DESKTOPDIRECTORY* = 0x00000019 # %PROFILEPATH%\All users\Desktop
|
|
||||||
CSIDL_APPDATA* = 0x0000001A # %USERPROFILE%\Application Data (roaming)
|
|
||||||
CSIDL_PRINTHOOD* = 0x0000001B # %USERPROFILE%\Printhood
|
|
||||||
CSIDL_LOCAL_APPDATA* = 0x0000001C # %USERPROFILE%\Local Settings\Application Data (non roaming)
|
|
||||||
CSIDL_COMMON_FAVORITES* = 0x0000001F # %PROFILEPATH%\All users\Favorites
|
|
||||||
CSIDL_INTERNET_CACHE* = 0x00000020 # %USERPROFILE%\Local Settings\Temporary Internet Files
|
|
||||||
CSIDL_COOKIES* = 0x00000021 # %USERPROFILE%\Cookies
|
|
||||||
CSIDL_HISTORY* = 0x00000022 # %USERPROFILE%\Local settings\History
|
|
||||||
CSIDL_COMMON_APPDATA* = 0x00000023 # %PROFILESPATH%\All Users\Application Data
|
|
||||||
CSIDL_WINDOWS* = 0x00000024 # %SYSTEMROOT%
|
|
||||||
CSIDL_SYSTEM* = 0x00000025 # %SYSTEMROOT%\SYSTEM32 (may be system on 95/98/ME)
|
|
||||||
CSIDL_PROGRAM_FILES* = 0x00000026 # %SYSTEMDRIVE%\Program Files
|
|
||||||
CSIDL_MYPICTURES* = 0x00000027 # %USERPROFILE%\My Documents\My Pictures
|
|
||||||
CSIDL_PROFILE* = 0x00000028 # %USERPROFILE%
|
|
||||||
CSIDL_PROGRAM_FILES_COMMON* = 0x0000002B # %SYSTEMDRIVE%\Program Files\Common
|
|
||||||
CSIDL_COMMON_TEMPLATES* = 0x0000002D # %PROFILEPATH%\All Users\Templates
|
|
||||||
CSIDL_COMMON_DOCUMENTS* = 0x0000002E # %PROFILEPATH%\All Users\Documents
|
|
||||||
CSIDL_COMMON_ADMINTOOLS* = 0x0000002F # %PROFILEPATH%\All Users\Start Menu\Programs\Administrative Tools
|
|
||||||
CSIDL_ADMINTOOLS* = 0x00000030 # %USERPROFILE%\Start Menu\Programs\Administrative Tools
|
|
||||||
CSIDL_COMMON_MUSIC* = 0x00000035 # %PROFILEPATH%\All Users\Documents\my music
|
|
||||||
CSIDL_COMMON_PICTURES* = 0x00000036 # %PROFILEPATH%\All Users\Documents\my pictures
|
|
||||||
CSIDL_COMMON_VIDEO* = 0x00000037 # %PROFILEPATH%\All Users\Documents\my videos
|
|
||||||
CSIDL_CDBURN_AREA* = 0x0000003B # %USERPROFILE%\Local Settings\Application Data\Microsoft\CD Burning
|
|
||||||
CSIDL_PROFILES* = 0x0000003E # %PROFILEPATH%
|
|
||||||
CSIDL_FLAG_CREATE* = 0x00008000 # (force creation of requested folder if it doesn't exist yet)
|
|
||||||
# Original entry points
|
|
||||||
|
|
||||||
proc SHGetFolderPathA*(Ahwnd: HWND, Csidl: int, Token: THandle, Flags: DWord,
|
|
||||||
Path: cstring): HRESULT{.stdcall, dynlib: LibName,
|
|
||||||
importc: "SHGetFolderPathA".}
|
|
||||||
proc SHGetFolderPathW*(Ahwnd: HWND, Csidl: int, Token: THandle, Flags: DWord,
|
|
||||||
Path: cstring): HRESULT{.stdcall, dynlib: LibName,
|
|
||||||
importc: "SHGetFolderPathW".}
|
|
||||||
proc SHGetFolderPath*(Ahwnd: HWND, Csidl: int, Token: THandle, Flags: DWord,
|
|
||||||
Path: cstring): HRESULT{.stdcall, dynlib: LibName,
|
|
||||||
importc: "SHGetFolderPathA".}
|
|
||||||
type
|
|
||||||
PFNSHGetFolderPathA* = proc (Ahwnd: HWND, Csidl: int, Token: THandle,
|
|
||||||
Flags: DWord, Path: cstring): HRESULT{.stdcall.}
|
|
||||||
PFNSHGetFolderPathW* = proc (Ahwnd: HWND, Csidl: int, Token: THandle,
|
|
||||||
Flags: DWord, Path: cstring): HRESULT{.stdcall.}
|
|
||||||
PFNSHGetFolderPath* = PFNSHGetFolderPathA
|
|
||||||
TSHGetFolderPathA* = PFNSHGetFolderPathA
|
|
||||||
TSHGetFolderPathW* = PFNSHGetFolderPathW
|
|
||||||
TSHGetFolderPath* = TSHGetFolderPathA
|
|
||||||
|
|
||||||
23945
lib/windows/windows.nim
23945
lib/windows/windows.nim
File diff suppressed because it is too large
Load diff
|
|
@ -334,6 +334,9 @@ const
|
||||||
|
|
||||||
proc WSAGetLastError*(): cint {.importc: "WSAGetLastError", dynlib: ws2dll.}
|
proc WSAGetLastError*(): cint {.importc: "WSAGetLastError", dynlib: ws2dll.}
|
||||||
|
|
||||||
|
type
|
||||||
|
TSocketHandle* = distinct int
|
||||||
|
|
||||||
type
|
type
|
||||||
TWSAData* {.pure, final, importc: "WSADATA", header: "Winsock2.h".} = object
|
TWSAData* {.pure, final, importc: "WSADATA", header: "Winsock2.h".} = object
|
||||||
wVersion, wHighVersion: int16
|
wVersion, wHighVersion: int16
|
||||||
|
|
@ -390,11 +393,9 @@ type
|
||||||
h_length*: int16
|
h_length*: int16
|
||||||
h_addr_list*: cstringArray
|
h_addr_list*: cstringArray
|
||||||
|
|
||||||
TWinSocket* = cint
|
|
||||||
|
|
||||||
TFdSet* {.pure, final.} = object
|
TFdSet* {.pure, final.} = object
|
||||||
fd_count*: cint # unsigned
|
fd_count*: cint # unsigned
|
||||||
fd_array*: array[0..FD_SETSIZE-1, TWinSocket]
|
fd_array*: array[0..FD_SETSIZE-1, TSocketHandle]
|
||||||
|
|
||||||
TTimeval* {.pure, final.} = object
|
TTimeval* {.pure, final.} = object
|
||||||
tv_sec*, tv_usec*: int32
|
tv_sec*, tv_usec*: int32
|
||||||
|
|
@ -413,6 +414,22 @@ type
|
||||||
|
|
||||||
var
|
var
|
||||||
SOMAXCONN* {.importc, header: "Winsock2.h".}: cint
|
SOMAXCONN* {.importc, header: "Winsock2.h".}: cint
|
||||||
|
INVALID_SOCKET* {.importc, header: "Winsock2.h".}: TSocketHandle
|
||||||
|
SOL_SOCKET* {.importc, header: "Winsock2.h".}: cint
|
||||||
|
SO_DEBUG* {.importc, header: "Winsock2.h".}: cint ## turn on debugging info recording
|
||||||
|
SO_ACCEPTCONN* {.importc, header: "Winsock2.h".}: cint # socket has had listen()
|
||||||
|
SO_REUSEADDR* {.importc, header: "Winsock2.h".}: cint # allow local address reuse
|
||||||
|
SO_KEEPALIVE* {.importc, header: "Winsock2.h".}: cint # keep connections alive
|
||||||
|
SO_DONTROUTE* {.importc, header: "Winsock2.h".}: cint # just use interface addresses
|
||||||
|
SO_BROADCAST* {.importc, header: "Winsock2.h".}: cint # permit sending of broadcast msgs
|
||||||
|
SO_USELOOPBACK* {.importc, header: "Winsock2.h".}: cint # bypass hardware when possible
|
||||||
|
SO_LINGER* {.importc, header: "Winsock2.h".}: cint # linger on close if data present
|
||||||
|
SO_OOBINLINE* {.importc, header: "Winsock2.h".}: cint # leave received OOB data in line
|
||||||
|
|
||||||
|
SO_DONTLINGER* {.importc, header: "Winsock2.h".}: cint
|
||||||
|
SO_EXCLUSIVEADDRUSE* {.importc, header: "Winsock2.h".}: cint # disallow local address reuse
|
||||||
|
|
||||||
|
proc `==`*(x, y: TSocketHandle): bool {.borrow.}
|
||||||
|
|
||||||
proc getservbyname*(name, proto: cstring): ptr TServent {.
|
proc getservbyname*(name, proto: cstring): ptr TServent {.
|
||||||
stdcall, importc: "getservbyname", dynlib: ws2dll.}
|
stdcall, importc: "getservbyname", dynlib: ws2dll.}
|
||||||
|
|
@ -426,45 +443,45 @@ proc gethostbyaddr*(ip: ptr TInAddr, len: cuint, theType: cint): ptr THostEnt {.
|
||||||
proc gethostbyname*(name: cstring): ptr THostEnt {.
|
proc gethostbyname*(name: cstring): ptr THostEnt {.
|
||||||
stdcall, importc: "gethostbyname", dynlib: ws2dll.}
|
stdcall, importc: "gethostbyname", dynlib: ws2dll.}
|
||||||
|
|
||||||
proc socket*(af, typ, protocol: cint): TWinSocket {.
|
proc socket*(af, typ, protocol: cint): TSocketHandle {.
|
||||||
stdcall, importc: "socket", dynlib: ws2dll.}
|
stdcall, importc: "socket", dynlib: ws2dll.}
|
||||||
|
|
||||||
proc closesocket*(s: TWinSocket): cint {.
|
proc closesocket*(s: TSocketHandle): cint {.
|
||||||
stdcall, importc: "closesocket", dynlib: ws2dll.}
|
stdcall, importc: "closesocket", dynlib: ws2dll.}
|
||||||
|
|
||||||
proc accept*(s: TWinSocket, a: ptr TSockAddr, addrlen: ptr TSockLen): TWinSocket {.
|
proc accept*(s: TSocketHandle, a: ptr TSockAddr, addrlen: ptr TSockLen): TSocketHandle {.
|
||||||
stdcall, importc: "accept", dynlib: ws2dll.}
|
stdcall, importc: "accept", dynlib: ws2dll.}
|
||||||
proc bindSocket*(s: TWinSocket, name: ptr TSockAddr, namelen: TSockLen): cint {.
|
proc bindSocket*(s: TSocketHandle, name: ptr TSockAddr, namelen: TSockLen): cint {.
|
||||||
stdcall, importc: "bind", dynlib: ws2dll.}
|
stdcall, importc: "bind", dynlib: ws2dll.}
|
||||||
proc connect*(s: TWinSocket, name: ptr TSockAddr, namelen: TSockLen): cint {.
|
proc connect*(s: TSocketHandle, name: ptr TSockAddr, namelen: TSockLen): cint {.
|
||||||
stdcall, importc: "connect", dynlib: ws2dll.}
|
stdcall, importc: "connect", dynlib: ws2dll.}
|
||||||
proc getsockname*(s: TWinSocket, name: ptr TSockAddr,
|
proc getsockname*(s: TSocketHandle, name: ptr TSockAddr,
|
||||||
namelen: ptr TSockLen): cint {.
|
namelen: ptr TSockLen): cint {.
|
||||||
stdcall, importc: "getsockname", dynlib: ws2dll.}
|
stdcall, importc: "getsockname", dynlib: ws2dll.}
|
||||||
proc getsockopt*(s: TWinSocket, level, optname: cint, optval: pointer,
|
proc getsockopt*(s: TSocketHandle, level, optname: cint, optval: pointer,
|
||||||
optlen: ptr TSockLen): cint {.
|
optlen: ptr TSockLen): cint {.
|
||||||
stdcall, importc: "getsockopt", dynlib: ws2dll.}
|
stdcall, importc: "getsockopt", dynlib: ws2dll.}
|
||||||
proc setsockopt*(s: TWinSocket, level, optname: cint, optval: pointer,
|
proc setsockopt*(s: TSocketHandle, level, optname: cint, optval: pointer,
|
||||||
optlen: TSockLen): cint {.
|
optlen: TSockLen): cint {.
|
||||||
stdcall, importc: "setsockopt", dynlib: ws2dll.}
|
stdcall, importc: "setsockopt", dynlib: ws2dll.}
|
||||||
|
|
||||||
proc listen*(s: TWinSocket, backlog: cint): cint {.
|
proc listen*(s: TSocketHandle, backlog: cint): cint {.
|
||||||
stdcall, importc: "listen", dynlib: ws2dll.}
|
stdcall, importc: "listen", dynlib: ws2dll.}
|
||||||
proc recv*(s: TWinSocket, buf: pointer, len, flags: cint): cint {.
|
proc recv*(s: TSocketHandle, buf: pointer, len, flags: cint): cint {.
|
||||||
stdcall, importc: "recv", dynlib: ws2dll.}
|
stdcall, importc: "recv", dynlib: ws2dll.}
|
||||||
proc recvfrom*(s: TWinSocket, buf: cstring, len, flags: cint,
|
proc recvfrom*(s: TSocketHandle, buf: cstring, len, flags: cint,
|
||||||
fromm: ptr TSockAddr, fromlen: ptr Tsocklen): cint {.
|
fromm: ptr TSockAddr, fromlen: ptr Tsocklen): cint {.
|
||||||
stdcall, importc: "recvfrom", dynlib: ws2dll.}
|
stdcall, importc: "recvfrom", dynlib: ws2dll.}
|
||||||
proc select*(nfds: cint, readfds, writefds, exceptfds: ptr TFdSet,
|
proc select*(nfds: cint, readfds, writefds, exceptfds: ptr TFdSet,
|
||||||
timeout: ptr TTimeval): cint {.
|
timeout: ptr TTimeval): cint {.
|
||||||
stdcall, importc: "select", dynlib: ws2dll.}
|
stdcall, importc: "select", dynlib: ws2dll.}
|
||||||
proc send*(s: TWinSocket, buf: pointer, len, flags: cint): cint {.
|
proc send*(s: TSocketHandle, buf: pointer, len, flags: cint): cint {.
|
||||||
stdcall, importc: "send", dynlib: ws2dll.}
|
stdcall, importc: "send", dynlib: ws2dll.}
|
||||||
proc sendto*(s: TWinSocket, buf: pointer, len, flags: cint,
|
proc sendto*(s: TSocketHandle, buf: pointer, len, flags: cint,
|
||||||
to: ptr TSockAddr, tolen: Tsocklen): cint {.
|
to: ptr TSockAddr, tolen: Tsocklen): cint {.
|
||||||
stdcall, importc: "sendto", dynlib: ws2dll.}
|
stdcall, importc: "sendto", dynlib: ws2dll.}
|
||||||
|
|
||||||
proc shutdown*(s: TWinSocket, how: cint): cint {.
|
proc shutdown*(s: TSocketHandle, how: cint): cint {.
|
||||||
stdcall, importc: "shutdown", dynlib: ws2dll.}
|
stdcall, importc: "shutdown", dynlib: ws2dll.}
|
||||||
|
|
||||||
proc getnameinfo*(a1: ptr Tsockaddr, a2: Tsocklen,
|
proc getnameinfo*(a1: ptr Tsockaddr, a2: Tsocklen,
|
||||||
|
|
@ -475,13 +492,13 @@ proc getnameinfo*(a1: ptr Tsockaddr, a2: Tsocklen,
|
||||||
proc inet_addr*(cp: cstring): int32 {.
|
proc inet_addr*(cp: cstring): int32 {.
|
||||||
stdcall, importc: "inet_addr", dynlib: ws2dll.}
|
stdcall, importc: "inet_addr", dynlib: ws2dll.}
|
||||||
|
|
||||||
proc WSAFDIsSet(s: TWinSocket, FDSet: var TFDSet): bool {.
|
proc WSAFDIsSet(s: TSocketHandle, FDSet: var TFDSet): bool {.
|
||||||
stdcall, importc: "__WSAFDIsSet", dynlib: ws2dll.}
|
stdcall, importc: "__WSAFDIsSet", dynlib: ws2dll.}
|
||||||
|
|
||||||
proc FD_ISSET*(Socket: TWinSocket, FDSet: var TFDSet): cint =
|
proc FD_ISSET*(Socket: TSocketHandle, FDSet: var TFDSet): cint =
|
||||||
result = if WSAFDIsSet(Socket, FDSet): 1'i32 else: 0'i32
|
result = if WSAFDIsSet(Socket, FDSet): 1'i32 else: 0'i32
|
||||||
|
|
||||||
proc FD_SET*(Socket: TWinSocket, FDSet: var TFDSet) =
|
proc FD_SET*(Socket: TSocketHandle, FDSet: var TFDSet) =
|
||||||
if FDSet.fd_count < FD_SETSIZE:
|
if FDSet.fd_count < FD_SETSIZE:
|
||||||
FDSet.fd_array[int(FDSet.fd_count)] = Socket
|
FDSet.fd_array[int(FDSet.fd_count)] = Socket
|
||||||
inc(FDSet.fd_count)
|
inc(FDSet.fd_count)
|
||||||
|
|
|
||||||
|
|
@ -1,733 +0,0 @@
|
||||||
#* cairo - a vector graphics library with display and print output
|
|
||||||
# *
|
|
||||||
# * Copyright © 2002 University of Southern California
|
|
||||||
# * Copyright © 2005 Red Hat, Inc.
|
|
||||||
# *
|
|
||||||
# * This library is free software; you can redistribute it and/or
|
|
||||||
# * modify it either under the terms of the GNU Lesser General Public
|
|
||||||
# * License version 2.1 as published by the Free Software Foundation
|
|
||||||
# * (the "LGPL") or, at your option, under the terms of the Mozilla
|
|
||||||
# * Public License Version 1.1 (the "MPL"). If you do not alter this
|
|
||||||
# * notice, a recipient may use your version of this file under either
|
|
||||||
# * the MPL or the LGPL.
|
|
||||||
# *
|
|
||||||
# * You should have received a copy of the LGPL along with this library
|
|
||||||
# * in the file COPYING-LGPL-2.1; if not, write to the Free Software
|
|
||||||
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
# * You should have received a copy of the MPL along with this library
|
|
||||||
# * in the file COPYING-MPL-1.1
|
|
||||||
# *
|
|
||||||
# * The contents of this file are subject to the Mozilla Public License
|
|
||||||
# * Version 1.1 (the "License"); you may not use this file except in
|
|
||||||
# * compliance with the License. You may obtain a copy of the License at
|
|
||||||
# * http://www.mozilla.org/MPL/
|
|
||||||
# *
|
|
||||||
# * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
|
|
||||||
# * OF ANY KIND, either express or implied. See the LGPL or the MPL for
|
|
||||||
# * the specific language governing rights and limitations.
|
|
||||||
# *
|
|
||||||
# * The Original Code is the cairo graphics library.
|
|
||||||
# *
|
|
||||||
# * The Initial Developer of the Original Code is University of Southern
|
|
||||||
# * California.
|
|
||||||
# *
|
|
||||||
# * Contributor(s):
|
|
||||||
# * Carl D. Worth <cworth@cworth.org>
|
|
||||||
# #*
|
|
||||||
# * This FreePascal binding generated August 26, 2005
|
|
||||||
# * by Jeffrey Pohlmeyer <yetanothergeek@yahoo.com>
|
|
||||||
#
|
|
||||||
|
|
||||||
#
|
|
||||||
# - Updated to cairo version 1.4
|
|
||||||
# - Grouped OS specific fuctions in separated units
|
|
||||||
# - Organized the functions by group and ordered exactly as the c header
|
|
||||||
# - Cleared parameter list syntax according to pascal standard
|
|
||||||
#
|
|
||||||
# By Luiz Américo Pereira Câmara
|
|
||||||
# October 2007
|
|
||||||
#
|
|
||||||
|
|
||||||
include "cairo_pragma.nim"
|
|
||||||
|
|
||||||
type
|
|
||||||
PByte = cstring
|
|
||||||
TStatus* = enum
|
|
||||||
STATUS_SUCCESS = 0,
|
|
||||||
STATUS_NO_MEMORY,
|
|
||||||
STATUS_INVALID_RESTORE,
|
|
||||||
STATUS_INVALID_POP_GROUP,
|
|
||||||
STATUS_NO_CURRENT_POINT,
|
|
||||||
STATUS_INVALID_MATRIX,
|
|
||||||
STATUS_INVALID_STATUS,
|
|
||||||
STATUS_NULL_POINTER,
|
|
||||||
STATUS_INVALID_STRING,
|
|
||||||
STATUS_INVALID_PATH_DATA,
|
|
||||||
STATUS_READ_ERROR,
|
|
||||||
STATUS_WRITE_ERROR,
|
|
||||||
STATUS_SURFACE_FINISHED,
|
|
||||||
STATUS_SURFACE_TYPE_MISMATCH,
|
|
||||||
STATUS_PATTERN_TYPE_MISMATCH,
|
|
||||||
STATUS_INVALID_CONTENT,
|
|
||||||
STATUS_INVALID_FORMAT,
|
|
||||||
STATUS_INVALID_VISUAL,
|
|
||||||
STATUS_FILE_NOT_FOUND,
|
|
||||||
STATUS_INVALID_DASH,
|
|
||||||
STATUS_INVALID_DSC_COMMENT,
|
|
||||||
STATUS_INVALID_INDEX,
|
|
||||||
STATUS_CLIP_NOT_REPRESENTABLE,
|
|
||||||
STATUS_TEMP_FILE_ERROR,
|
|
||||||
STATUS_INVALID_STRIDE,
|
|
||||||
STATUS_FONT_TYPE_MISMATCH,
|
|
||||||
STATUS_USER_FONT_IMMUTABLE,
|
|
||||||
STATUS_USER_FONT_ERROR,
|
|
||||||
STATUS_NEGATIVE_COUNT,
|
|
||||||
STATUS_INVALID_CLUSTERS,
|
|
||||||
STATUS_INVALID_SLANT,
|
|
||||||
STATUS_INVALID_WEIGHT
|
|
||||||
|
|
||||||
|
|
||||||
TOperator* = enum
|
|
||||||
OPERATOR_CLEAR, OPERATOR_SOURCE, OPERATOR_OVER, OPERATOR_IN, OPERATOR_OUT,
|
|
||||||
OPERATOR_ATOP, OPERATOR_DEST, OPERATOR_DEST_OVER, OPERATOR_DEST_IN,
|
|
||||||
OPERATOR_DEST_OUT, OPERATOR_DEST_ATOP, OPERATOR_XOR, OPERATOR_ADD,
|
|
||||||
OPERATOR_SATURATE
|
|
||||||
TAntialias* = enum
|
|
||||||
ANTIALIAS_DEFAULT, ANTIALIAS_NONE, ANTIALIAS_GRAY, ANTIALIAS_SUBPIXEL
|
|
||||||
TFillRule* = enum
|
|
||||||
FILL_RULE_WINDING, FILL_RULE_EVEN_ODD
|
|
||||||
TLineCap* = enum
|
|
||||||
LINE_CAP_BUTT, LINE_CAP_ROUND, LINE_CAP_SQUARE
|
|
||||||
TLineJoin* = enum
|
|
||||||
LINE_JOIN_MITER, LINE_JOIN_ROUND, LINE_JOIN_BEVEL
|
|
||||||
TFontSlant* = enum
|
|
||||||
FONT_SLANT_NORMAL, FONT_SLANT_ITALIC, FONT_SLANT_OBLIQUE
|
|
||||||
TFontWeight* = enum
|
|
||||||
FONT_WEIGHT_NORMAL, FONT_WEIGHT_BOLD
|
|
||||||
TSubpixelOrder* = enum
|
|
||||||
SUBPIXEL_ORDER_DEFAULT, SUBPIXEL_ORDER_RGB, SUBPIXEL_ORDER_BGR,
|
|
||||||
SUBPIXEL_ORDER_VRGB, SUBPIXEL_ORDER_VBGR
|
|
||||||
THintStyle* = enum
|
|
||||||
HINT_STYLE_DEFAULT, HINT_STYLE_NONE, HINT_STYLE_SLIGHT, HINT_STYLE_MEDIUM,
|
|
||||||
HINT_STYLE_FULL
|
|
||||||
THintMetrics* = enum
|
|
||||||
HINT_METRICS_DEFAULT, HINT_METRICS_OFF, HINT_METRICS_ON
|
|
||||||
TPathDataType* = enum
|
|
||||||
PATH_MOVE_TO, PATH_LINE_TO, PATH_CURVE_TO, PATH_CLOSE_PATH
|
|
||||||
TContent* = enum
|
|
||||||
CONTENT_COLOR = 0x00001000, CONTENT_ALPHA = 0x00002000,
|
|
||||||
CONTENT_COLOR_ALPHA = 0x00003000
|
|
||||||
TFormat* = enum
|
|
||||||
FORMAT_ARGB32, FORMAT_RGB24, FORMAT_A8, FORMAT_A1
|
|
||||||
TExtend* = enum
|
|
||||||
EXTEND_NONE, EXTEND_REPEAT, EXTEND_REFLECT, EXTEND_PAD
|
|
||||||
TFilter* = enum
|
|
||||||
FILTER_FAST, FILTER_GOOD, FILTER_BEST, FILTER_NEAREST, FILTER_BILINEAR,
|
|
||||||
FILTER_GAUSSIAN
|
|
||||||
TFontType* = enum
|
|
||||||
FONT_TYPE_TOY, FONT_TYPE_FT, FONT_TYPE_WIN32, FONT_TYPE_ATSUI
|
|
||||||
TPatternType* = enum
|
|
||||||
PATTERN_TYPE_SOLID, PATTERN_TYPE_SURFACE, PATTERN_TYPE_LINEAR,
|
|
||||||
PATTERN_TYPE_RADIAL
|
|
||||||
TSurfaceType* = enum
|
|
||||||
SURFACE_TYPE_IMAGE, SURFACE_TYPE_PDF, SURFACE_TYPE_PS, SURFACE_TYPE_XLIB,
|
|
||||||
SURFACE_TYPE_XCB, SURFACE_TYPE_GLITZ, SURFACE_TYPE_QUARTZ,
|
|
||||||
SURFACE_TYPE_WIN32, SURFACE_TYPE_BEOS, SURFACE_TYPE_DIRECTFB,
|
|
||||||
SURFACE_TYPE_SVG, SURFACE_TYPE_OS2
|
|
||||||
TSvgVersion* = enum
|
|
||||||
SVG_VERSION_1_1, SVG_VERSION_1_2
|
|
||||||
PSurface* = ptr TSurface
|
|
||||||
PPSurface* = ptr PSurface
|
|
||||||
PContext* = ptr TContext
|
|
||||||
PPattern* = ptr TPattern
|
|
||||||
PFontOptions* = ptr TFontOptions
|
|
||||||
PFontFace* = ptr TFontFace
|
|
||||||
PScaledFont* = ptr TScaledFont
|
|
||||||
PBool* = ptr TBool
|
|
||||||
TBool* = int32
|
|
||||||
PMatrix* = ptr TMatrix
|
|
||||||
PUserDataKey* = ptr TUserDataKey
|
|
||||||
PGlyph* = ptr TGlyph
|
|
||||||
PTextExtents* = ptr TTextExtents
|
|
||||||
PFontExtents* = ptr TFontExtents
|
|
||||||
PPathDataType* = ptr TPathDataType
|
|
||||||
PPathData* = ptr TPathData
|
|
||||||
PPath* = ptr TPath
|
|
||||||
PRectangle* = ptr TRectangle
|
|
||||||
PRectangleList* = ptr TRectangleList
|
|
||||||
TDestroyFunc* = proc (data: Pointer){.cdecl.}
|
|
||||||
TWriteFunc* = proc (closure: Pointer, data: PByte, len: int32): TStatus{.cdecl.}
|
|
||||||
TReadFunc* = proc (closure: Pointer, data: PByte, len: int32): TStatus{.cdecl.}
|
|
||||||
TContext*{.final.} = object #OPAQUE
|
|
||||||
TSurface*{.final.} = object #OPAQUE
|
|
||||||
TPattern*{.final.} = object #OPAQUE
|
|
||||||
TScaledFont*{.final.} = object #OPAQUE
|
|
||||||
TFontFace*{.final.} = object #OPAQUE
|
|
||||||
TFontOptions*{.final.} = object #OPAQUE
|
|
||||||
TMatrix*{.final.} = object
|
|
||||||
xx: float64
|
|
||||||
yx: float64
|
|
||||||
xy: float64
|
|
||||||
yy: float64
|
|
||||||
x0: float64
|
|
||||||
y0: float64
|
|
||||||
|
|
||||||
TUserDataKey*{.final.} = object
|
|
||||||
unused: int32
|
|
||||||
|
|
||||||
TGlyph*{.final.} = object
|
|
||||||
index: int32
|
|
||||||
x: float64
|
|
||||||
y: float64
|
|
||||||
|
|
||||||
TTextExtents*{.final.} = object
|
|
||||||
x_bearing: float64
|
|
||||||
y_bearing: float64
|
|
||||||
width: float64
|
|
||||||
height: float64
|
|
||||||
x_advance: float64
|
|
||||||
y_advance: float64
|
|
||||||
|
|
||||||
TFontExtents*{.final.} = object
|
|
||||||
ascent: float64
|
|
||||||
descent: float64
|
|
||||||
height: float64
|
|
||||||
max_x_advance: float64
|
|
||||||
max_y_advance: float64
|
|
||||||
|
|
||||||
TPathData*{.final.} = object #* _type : TCairoPathDataType;
|
|
||||||
# length : LongInt;
|
|
||||||
# end
|
|
||||||
x: float64
|
|
||||||
y: float64
|
|
||||||
|
|
||||||
TPath*{.final.} = object
|
|
||||||
status: TStatus
|
|
||||||
data: PPathData
|
|
||||||
num_data: int32
|
|
||||||
|
|
||||||
TRectangle*{.final.} = object
|
|
||||||
x, y, width, height: float64
|
|
||||||
|
|
||||||
TRectangleList*{.final.} = object
|
|
||||||
status: TStatus
|
|
||||||
rectangles: PRectangle
|
|
||||||
num_rectangles: int32
|
|
||||||
|
|
||||||
|
|
||||||
proc version*(): int32{.cdecl, importc: "cairo_version", libcairo.}
|
|
||||||
proc version_string*(): cstring{.cdecl, importc: "cairo_version_string",
|
|
||||||
libcairo.}
|
|
||||||
#Helper function to retrieve decoded version
|
|
||||||
proc version*(major, minor, micro: var int32)
|
|
||||||
#* Functions for manipulating state objects
|
|
||||||
proc create*(target: PSurface): PContext{.cdecl, importc: "cairo_create",
|
|
||||||
libcairo.}
|
|
||||||
proc reference*(cr: PContext): PContext{.cdecl, importc: "cairo_reference", libcairo.}
|
|
||||||
proc destroy*(cr: PContext){.cdecl, importc: "cairo_destroy", libcairo.}
|
|
||||||
proc get_reference_count*(cr: PContext): int32{.cdecl,
|
|
||||||
importc: "cairo_get_reference_count", libcairo.}
|
|
||||||
proc get_user_data*(cr: PContext, key: PUserDataKey): pointer{.cdecl,
|
|
||||||
importc: "cairo_get_user_data", libcairo.}
|
|
||||||
proc set_user_data*(cr: PContext, key: PUserDataKey, user_data: Pointer,
|
|
||||||
destroy: TDestroyFunc): TStatus{.cdecl,
|
|
||||||
importc: "cairo_set_user_data", libcairo.}
|
|
||||||
proc save*(cr: PContext){.cdecl, importc: "cairo_save", libcairo.}
|
|
||||||
proc restore*(cr: PContext){.cdecl, importc: "cairo_restore", libcairo.}
|
|
||||||
proc push_group*(cr: PContext){.cdecl, importc: "cairo_push_group", libcairo.}
|
|
||||||
proc push_group_with_content*(cr: PContext, content: TContent){.cdecl,
|
|
||||||
importc: "cairo_push_group_with_content", libcairo.}
|
|
||||||
proc pop_group*(cr: PContext): PPattern{.cdecl, importc: "cairo_pop_group",
|
|
||||||
libcairo.}
|
|
||||||
proc pop_group_to_source*(cr: PContext){.cdecl, importc: "cairo_pop_group_to_source",
|
|
||||||
libcairo.}
|
|
||||||
#* Modify state
|
|
||||||
proc set_operator*(cr: PContext, op: TOperator){.cdecl, importc: "cairo_set_operator",
|
|
||||||
libcairo.}
|
|
||||||
proc set_source*(cr: PContext, source: PPattern){.cdecl, importc: "cairo_set_source",
|
|
||||||
libcairo.}
|
|
||||||
proc set_source_rgb*(cr: PContext, red, green, blue: float64){.cdecl,
|
|
||||||
importc: "cairo_set_source_rgb", libcairo.}
|
|
||||||
proc set_source_rgba*(cr: PContext, red, green, blue, alpha: float64){.cdecl,
|
|
||||||
importc: "cairo_set_source_rgba", libcairo.}
|
|
||||||
proc set_source*(cr: PContext, surface: PSurface, x, y: float64){.cdecl,
|
|
||||||
importc: "cairo_set_source_surface", libcairo.}
|
|
||||||
proc set_tolerance*(cr: PContext, tolerance: float64){.cdecl,
|
|
||||||
importc: "cairo_set_tolerance", libcairo.}
|
|
||||||
proc set_antialias*(cr: PContext, antialias: TAntialias){.cdecl,
|
|
||||||
importc: "cairo_set_antialias", libcairo.}
|
|
||||||
proc set_fill_rule*(cr: PContext, fill_rule: TFillRule){.cdecl,
|
|
||||||
importc: "cairo_set_fill_rule", libcairo.}
|
|
||||||
proc set_line_width*(cr: PContext, width: float64){.cdecl,
|
|
||||||
importc: "cairo_set_line_width", libcairo.}
|
|
||||||
proc set_line_cap*(cr: PContext, line_cap: TLineCap){.cdecl,
|
|
||||||
importc: "cairo_set_line_cap", libcairo.}
|
|
||||||
proc set_line_join*(cr: PContext, line_join: TLineJoin){.cdecl,
|
|
||||||
importc: "cairo_set_line_join", libcairo.}
|
|
||||||
proc set_dash*(cr: PContext, dashes: openarray[float64], offset: float64){.cdecl,
|
|
||||||
importc: "cairo_set_dash", libcairo.}
|
|
||||||
proc set_miter_limit*(cr: PContext, limit: float64){.cdecl,
|
|
||||||
importc: "cairo_set_miter_limit", libcairo.}
|
|
||||||
proc translate*(cr: PContext, tx, ty: float64){.cdecl, importc: "cairo_translate",
|
|
||||||
libcairo.}
|
|
||||||
proc scale*(cr: PContext, sx, sy: float64){.cdecl, importc: "cairo_scale",
|
|
||||||
libcairo.}
|
|
||||||
proc rotate*(cr: PContext, angle: float64){.cdecl, importc: "cairo_rotate",
|
|
||||||
libcairo.}
|
|
||||||
proc transform*(cr: PContext, matrix: PMatrix){.cdecl, importc: "cairo_transform",
|
|
||||||
libcairo.}
|
|
||||||
proc set_matrix*(cr: PContext, matrix: PMatrix){.cdecl, importc: "cairo_set_matrix",
|
|
||||||
libcairo.}
|
|
||||||
proc identity_matrix*(cr: PContext){.cdecl, importc: "cairo_identity_matrix",
|
|
||||||
libcairo.}
|
|
||||||
proc user_to_device*(cr: PContext, x, y: var float64){.cdecl,
|
|
||||||
importc: "cairo_user_to_device", libcairo.}
|
|
||||||
proc user_to_device_distance*(cr: PContext, dx, dy: var float64){.cdecl,
|
|
||||||
importc: "cairo_user_to_device_distance", libcairo.}
|
|
||||||
proc device_to_user*(cr: PContext, x, y: var float64){.cdecl,
|
|
||||||
importc: "cairo_device_to_user", libcairo.}
|
|
||||||
proc device_to_user_distance*(cr: PContext, dx, dy: var float64){.cdecl,
|
|
||||||
importc: "cairo_device_to_user_distance", libcairo.}
|
|
||||||
#* Path creation functions
|
|
||||||
proc new_path*(cr: PContext){.cdecl, importc: "cairo_new_path", libcairo.}
|
|
||||||
proc move_to*(cr: PContext, x, y: float64){.cdecl, importc: "cairo_move_to",
|
|
||||||
libcairo.}
|
|
||||||
proc new_sub_path*(cr: PContext){.cdecl, importc: "cairo_new_sub_path",
|
|
||||||
libcairo.}
|
|
||||||
proc line_to*(cr: PContext, x, y: float64){.cdecl, importc: "cairo_line_to",
|
|
||||||
libcairo.}
|
|
||||||
proc curve_to*(cr: PContext, x1, y1, x2, y2, x3, y3: float64){.cdecl,
|
|
||||||
importc: "cairo_curve_to", libcairo.}
|
|
||||||
proc arc*(cr: PContext, xc, yc, radius, angle1, angle2: float64){.cdecl,
|
|
||||||
importc: "cairo_arc", libcairo.}
|
|
||||||
proc arc_negative*(cr: PContext, xc, yc, radius, angle1, angle2: float64){.cdecl,
|
|
||||||
importc: "cairo_arc_negative", libcairo.}
|
|
||||||
proc rel_move_to*(cr: PContext, dx, dy: float64){.cdecl, importc: "cairo_rel_move_to",
|
|
||||||
libcairo.}
|
|
||||||
proc rel_line_to*(cr: PContext, dx, dy: float64){.cdecl, importc: "cairo_rel_line_to",
|
|
||||||
libcairo.}
|
|
||||||
proc rel_curve_to*(cr: PContext, dx1, dy1, dx2, dy2, dx3, dy3: float64){.cdecl,
|
|
||||||
importc: "cairo_rel_curve_to", libcairo.}
|
|
||||||
proc rectangle*(cr: PContext, x, y, width, height: float64){.cdecl,
|
|
||||||
importc: "cairo_rectangle", libcairo.}
|
|
||||||
proc close_path*(cr: PContext){.cdecl, importc: "cairo_close_path", libcairo.}
|
|
||||||
#* Painting functions
|
|
||||||
proc paint*(cr: PContext){.cdecl, importc: "cairo_paint", libcairo.}
|
|
||||||
proc paint_with_alpha*(cr: PContext, alpha: float64){.cdecl,
|
|
||||||
importc: "cairo_paint_with_alpha", libcairo.}
|
|
||||||
proc mask*(cr: PContext, pattern: PPattern){.cdecl, importc: "cairo_mask",
|
|
||||||
libcairo.}
|
|
||||||
proc mask*(cr: PContext, surface: PSurface, surface_x, surface_y: float64){.
|
|
||||||
cdecl, importc: "cairo_mask_surface", libcairo.}
|
|
||||||
proc stroke*(cr: PContext){.cdecl, importc: "cairo_stroke", libcairo.}
|
|
||||||
proc stroke_preserve*(cr: PContext){.cdecl, importc: "cairo_stroke_preserve",
|
|
||||||
libcairo.}
|
|
||||||
proc fill*(cr: PContext){.cdecl, importc: "cairo_fill", libcairo.}
|
|
||||||
proc fill_preserve*(cr: PContext){.cdecl, importc: "cairo_fill_preserve",
|
|
||||||
libcairo.}
|
|
||||||
proc copy_page*(cr: PContext){.cdecl, importc: "cairo_copy_page", libcairo.}
|
|
||||||
proc show_page*(cr: PContext){.cdecl, importc: "cairo_show_page", libcairo.}
|
|
||||||
#* Insideness testing
|
|
||||||
proc in_stroke*(cr: PContext, x, y: float64): TBool{.cdecl, importc: "cairo_in_stroke",
|
|
||||||
libcairo.}
|
|
||||||
proc in_fill*(cr: PContext, x, y: float64): TBool{.cdecl, importc: "cairo_in_fill",
|
|
||||||
libcairo.}
|
|
||||||
#* Rectangular extents
|
|
||||||
proc stroke_extents*(cr: PContext, x1, y1, x2, y2: var float64){.cdecl,
|
|
||||||
importc: "cairo_stroke_extents", libcairo.}
|
|
||||||
proc fill_extents*(cr: PContext, x1, y1, x2, y2: var float64){.cdecl,
|
|
||||||
importc: "cairo_fill_extents", libcairo.}
|
|
||||||
#* Clipping
|
|
||||||
proc reset_clip*(cr: PContext){.cdecl, importc: "cairo_reset_clip", libcairo.}
|
|
||||||
proc clip*(cr: PContext){.cdecl, importc: "cairo_clip", libcairo.}
|
|
||||||
proc clip_preserve*(cr: PContext){.cdecl, importc: "cairo_clip_preserve",
|
|
||||||
libcairo.}
|
|
||||||
proc clip_extents*(cr: PContext, x1, y1, x2, y2: var float64){.cdecl,
|
|
||||||
importc: "cairo_clip_extents", libcairo.}
|
|
||||||
proc copy_clip_rectangle_list*(cr: PContext): PRectangleList{.cdecl,
|
|
||||||
importc: "cairo_copy_clip_rectangle_list", libcairo.}
|
|
||||||
proc rectangle_list_destroy*(rectangle_list: PRectangleList){.cdecl,
|
|
||||||
importc: "cairo_rectangle_list_destroy", libcairo.}
|
|
||||||
#* Font/Text functions
|
|
||||||
proc font_options_create*(): PFontOptions{.cdecl,
|
|
||||||
importc: "cairo_font_options_create", libcairo.}
|
|
||||||
proc copy*(original: PFontOptions): PFontOptions{.cdecl,
|
|
||||||
importc: "cairo_font_options_copy", libcairo.}
|
|
||||||
proc destroy*(options: PFontOptions){.cdecl,
|
|
||||||
importc: "cairo_font_options_destroy", libcairo.}
|
|
||||||
proc status*(options: PFontOptions): TStatus{.cdecl,
|
|
||||||
importc: "cairo_font_options_status", libcairo.}
|
|
||||||
proc merge*(options, other: PFontOptions){.cdecl,
|
|
||||||
importc: "cairo_font_options_merge", libcairo.}
|
|
||||||
proc equal*(options, other: PFontOptions): TBool{.cdecl,
|
|
||||||
importc: "cairo_font_options_equal", libcairo.}
|
|
||||||
proc hash*(options: PFontOptions): int32{.cdecl,
|
|
||||||
importc: "cairo_font_options_hash", libcairo.}
|
|
||||||
proc set_antialias*(options: PFontOptions, antialias: TAntialias){.
|
|
||||||
cdecl, importc: "cairo_font_options_set_antialias", libcairo.}
|
|
||||||
proc get_antialias*(options: PFontOptions): TAntialias{.cdecl,
|
|
||||||
importc: "cairo_font_options_get_antialias", libcairo.}
|
|
||||||
proc set_subpixel_order*(options: PFontOptions,
|
|
||||||
subpixel_order: TSubpixelOrder){.cdecl,
|
|
||||||
importc: "cairo_font_options_set_subpixel_order", libcairo.}
|
|
||||||
proc get_subpixel_order*(options: PFontOptions): TSubpixelOrder{.
|
|
||||||
cdecl, importc: "cairo_font_options_get_subpixel_order", libcairo.}
|
|
||||||
proc set_hint_style*(options: PFontOptions, hint_style: THintStyle){.
|
|
||||||
cdecl, importc: "cairo_font_options_set_hint_style", libcairo.}
|
|
||||||
proc get_hint_style*(options: PFontOptions): THintStyle{.cdecl,
|
|
||||||
importc: "cairo_font_options_get_hint_style", libcairo.}
|
|
||||||
proc set_hint_metrics*(options: PFontOptions,
|
|
||||||
hint_metrics: THintMetrics){.cdecl,
|
|
||||||
importc: "cairo_font_options_set_hint_metrics", libcairo.}
|
|
||||||
proc get_hint_metrics*(options: PFontOptions): THintMetrics{.cdecl,
|
|
||||||
importc: "cairo_font_options_get_hint_metrics", libcairo.}
|
|
||||||
#* This interface is for dealing with text as text, not caring about the
|
|
||||||
# font object inside the the TCairo.
|
|
||||||
proc select_font_face*(cr: PContext, family: cstring, slant: TFontSlant,
|
|
||||||
weight: TFontWeight){.cdecl,
|
|
||||||
importc: "cairo_select_font_face", libcairo.}
|
|
||||||
proc set_font_size*(cr: PContext, size: float64){.cdecl,
|
|
||||||
importc: "cairo_set_font_size", libcairo.}
|
|
||||||
proc set_font_matrix*(cr: PContext, matrix: PMatrix){.cdecl,
|
|
||||||
importc: "cairo_set_font_matrix", libcairo.}
|
|
||||||
proc get_font_matrix*(cr: PContext, matrix: PMatrix){.cdecl,
|
|
||||||
importc: "cairo_get_font_matrix", libcairo.}
|
|
||||||
proc set_font_options*(cr: PContext, options: PFontOptions){.cdecl,
|
|
||||||
importc: "cairo_set_font_options", libcairo.}
|
|
||||||
proc get_font_options*(cr: PContext, options: PFontOptions){.cdecl,
|
|
||||||
importc: "cairo_get_font_options", libcairo.}
|
|
||||||
proc set_font_face*(cr: PContext, font_face: PFontFace){.cdecl,
|
|
||||||
importc: "cairo_set_font_face", libcairo.}
|
|
||||||
proc get_font_face*(cr: PContext): PFontFace{.cdecl, importc: "cairo_get_font_face",
|
|
||||||
libcairo.}
|
|
||||||
proc set_scaled_font*(cr: PContext, scaled_font: PScaledFont){.cdecl,
|
|
||||||
importc: "cairo_set_scaled_font", libcairo.}
|
|
||||||
proc get_scaled_font*(cr: PContext): PScaledFont{.cdecl,
|
|
||||||
importc: "cairo_get_scaled_font", libcairo.}
|
|
||||||
proc show_text*(cr: PContext, utf8: cstring){.cdecl, importc: "cairo_show_text",
|
|
||||||
libcairo.}
|
|
||||||
proc show_glyphs*(cr: PContext, glyphs: PGlyph, num_glyphs: int32){.cdecl,
|
|
||||||
importc: "cairo_show_glyphs", libcairo.}
|
|
||||||
proc text_path*(cr: PContext, utf8: cstring){.cdecl, importc: "cairo_text_path",
|
|
||||||
libcairo.}
|
|
||||||
proc glyph_path*(cr: PContext, glyphs: PGlyph, num_glyphs: int32){.cdecl,
|
|
||||||
importc: "cairo_glyph_path", libcairo.}
|
|
||||||
proc text_extents*(cr: PContext, utf8: cstring, extents: PTextExtents){.cdecl,
|
|
||||||
importc: "cairo_text_extents", libcairo.}
|
|
||||||
proc glyph_extents*(cr: PContext, glyphs: PGlyph, num_glyphs: int32,
|
|
||||||
extents: PTextExtents){.cdecl,
|
|
||||||
importc: "cairo_glyph_extents", libcairo.}
|
|
||||||
proc font_extents*(cr: PContext, extents: PFontExtents){.cdecl,
|
|
||||||
importc: "cairo_font_extents", libcairo.}
|
|
||||||
#* Generic identifier for a font style
|
|
||||||
proc reference*(font_face: PFontFace): PFontFace{.cdecl,
|
|
||||||
importc: "cairo_font_face_reference", libcairo.}
|
|
||||||
proc destroy*(font_face: PFontFace){.cdecl,
|
|
||||||
importc: "cairo_font_face_destroy", libcairo.}
|
|
||||||
proc get_reference_count*(font_face: PFontFace): int32{.cdecl,
|
|
||||||
importc: "cairo_font_face_get_reference_count", libcairo.}
|
|
||||||
proc status*(font_face: PFontFace): TStatus{.cdecl,
|
|
||||||
importc: "cairo_font_face_status", libcairo.}
|
|
||||||
proc get_type*(font_face: PFontFace): TFontType{.cdecl,
|
|
||||||
importc: "cairo_font_face_get_type", libcairo.}
|
|
||||||
proc get_user_data*(font_face: PFontFace, key: PUserDataKey): pointer{.
|
|
||||||
cdecl, importc: "cairo_font_face_get_user_data", libcairo.}
|
|
||||||
proc set_user_data*(font_face: PFontFace, key: PUserDataKey,
|
|
||||||
user_data: pointer, destroy: TDestroyFunc): TStatus{.
|
|
||||||
cdecl, importc: "cairo_font_face_set_user_data", libcairo.}
|
|
||||||
#* Portable interface to general font features
|
|
||||||
proc scaled_font_create*(font_face: PFontFace, font_matrix: PMatrix,
|
|
||||||
ctm: PMatrix, options: PFontOptions): PScaledFont{.
|
|
||||||
cdecl, importc: "cairo_scaled_font_create", libcairo.}
|
|
||||||
proc reference*(scaled_font: PScaledFont): PScaledFont{.cdecl,
|
|
||||||
importc: "cairo_scaled_font_reference", libcairo.}
|
|
||||||
proc destroy*(scaled_font: PScaledFont){.cdecl,
|
|
||||||
importc: "cairo_scaled_font_destroy", libcairo.}
|
|
||||||
proc get_reference_count*(scaled_font: PScaledFont): int32{.cdecl,
|
|
||||||
importc: "cairo_scaled_font_get_reference_count", libcairo.}
|
|
||||||
proc status*(scaled_font: PScaledFont): TStatus{.cdecl,
|
|
||||||
importc: "cairo_scaled_font_status", libcairo.}
|
|
||||||
proc get_type*(scaled_font: PScaledFont): TFontType{.cdecl,
|
|
||||||
importc: "cairo_scaled_font_get_type", libcairo.}
|
|
||||||
proc get_user_data*(scaled_font: PScaledFont, key: PUserDataKey): Pointer{.
|
|
||||||
cdecl, importc: "cairo_scaled_font_get_user_data", libcairo.}
|
|
||||||
proc set_user_data*(scaled_font: PScaledFont, key: PUserDataKey,
|
|
||||||
user_data: Pointer, destroy: TDestroyFunc): TStatus{.
|
|
||||||
cdecl, importc: "cairo_scaled_font_set_user_data", libcairo.}
|
|
||||||
proc extents*(scaled_font: PScaledFont, extents: PFontExtents){.
|
|
||||||
cdecl, importc: "cairo_scaled_font_extents", libcairo.}
|
|
||||||
proc text_extents*(scaled_font: PScaledFont, utf8: cstring,
|
|
||||||
extents: PTextExtents){.cdecl,
|
|
||||||
importc: "cairo_scaled_font_text_extents", libcairo.}
|
|
||||||
proc glyph_extents*(scaled_font: PScaledFont, glyphs: PGlyph,
|
|
||||||
num_glyphs: int32, extents: PTextExtents){.
|
|
||||||
cdecl, importc: "cairo_scaled_font_glyph_extents", libcairo.}
|
|
||||||
proc get_font_face*(scaled_font: PScaledFont): PFontFace{.cdecl,
|
|
||||||
importc: "cairo_scaled_font_get_font_face", libcairo.}
|
|
||||||
proc get_font_matrix*(scaled_font: PScaledFont, font_matrix: PMatrix){.
|
|
||||||
cdecl, importc: "cairo_scaled_font_get_font_matrix", libcairo.}
|
|
||||||
proc get_ctm*(scaled_font: PScaledFont, ctm: PMatrix){.cdecl,
|
|
||||||
importc: "cairo_scaled_font_get_ctm", libcairo.}
|
|
||||||
proc get_font_options*(scaled_font: PScaledFont,
|
|
||||||
options: PFontOptions){.cdecl,
|
|
||||||
importc: "cairo_scaled_font_get_font_options", libcairo.}
|
|
||||||
#* Query functions
|
|
||||||
proc get_operator*(cr: PContext): TOperator{.cdecl, importc: "cairo_get_operator",
|
|
||||||
libcairo.}
|
|
||||||
proc get_source*(cr: PContext): PPattern{.cdecl, importc: "cairo_get_source",
|
|
||||||
libcairo.}
|
|
||||||
proc get_tolerance*(cr: PContext): float64{.cdecl, importc: "cairo_get_tolerance",
|
|
||||||
libcairo.}
|
|
||||||
proc get_antialias*(cr: PContext): TAntialias{.cdecl, importc: "cairo_get_antialias",
|
|
||||||
libcairo.}
|
|
||||||
proc get_current_point*(cr: PContext, x, y: var float64){.cdecl,
|
|
||||||
importc: "cairo_get_current_point", libcairo.}
|
|
||||||
proc get_fill_rule*(cr: PContext): TFillRule{.cdecl, importc: "cairo_get_fill_rule",
|
|
||||||
libcairo.}
|
|
||||||
proc get_line_width*(cr: PContext): float64{.cdecl, importc: "cairo_get_line_width",
|
|
||||||
libcairo.}
|
|
||||||
proc get_line_cap*(cr: PContext): TLineCap{.cdecl, importc: "cairo_get_line_cap",
|
|
||||||
libcairo.}
|
|
||||||
proc get_line_join*(cr: PContext): TLineJoin{.cdecl, importc: "cairo_get_line_join",
|
|
||||||
libcairo.}
|
|
||||||
proc get_miter_limit*(cr: PContext): float64{.cdecl, importc: "cairo_get_miter_limit",
|
|
||||||
libcairo.}
|
|
||||||
proc get_dash_count*(cr: PContext): int32{.cdecl, importc: "cairo_get_dash_count",
|
|
||||||
libcairo.}
|
|
||||||
proc get_dash*(cr: PContext, dashes, offset: var float64){.cdecl,
|
|
||||||
importc: "cairo_get_dash", libcairo.}
|
|
||||||
proc get_matrix*(cr: PContext, matrix: PMatrix){.cdecl, importc: "cairo_get_matrix",
|
|
||||||
libcairo.}
|
|
||||||
proc get_target*(cr: PContext): PSurface{.cdecl, importc: "cairo_get_target",
|
|
||||||
libcairo.}
|
|
||||||
proc get_group_target*(cr: PContext): PSurface{.cdecl,
|
|
||||||
importc: "cairo_get_group_target", libcairo.}
|
|
||||||
proc copy_path*(cr: PContext): PPath{.cdecl, importc: "cairo_copy_path",
|
|
||||||
libcairo.}
|
|
||||||
proc copy_path_flat*(cr: PContext): PPath{.cdecl, importc: "cairo_copy_path_flat",
|
|
||||||
libcairo.}
|
|
||||||
proc append_path*(cr: PContext, path: PPath){.cdecl, importc: "cairo_append_path",
|
|
||||||
libcairo.}
|
|
||||||
proc destroy*(path: PPath){.cdecl, importc: "cairo_path_destroy",
|
|
||||||
libcairo.}
|
|
||||||
#* Error status queries
|
|
||||||
proc status*(cr: PContext): TStatus{.cdecl, importc: "cairo_status", libcairo.}
|
|
||||||
proc status_to_string*(status: TStatus): cstring{.cdecl,
|
|
||||||
importc: "cairo_status_to_string", libcairo.}
|
|
||||||
#* Surface manipulation
|
|
||||||
proc surface_create_similar*(other: PSurface, content: TContent,
|
|
||||||
width, height: int32): PSurface{.cdecl,
|
|
||||||
importc: "cairo_surface_create_similar", libcairo.}
|
|
||||||
proc reference*(surface: PSurface): PSurface{.cdecl,
|
|
||||||
importc: "cairo_surface_reference", libcairo.}
|
|
||||||
proc finish*(surface: PSurface){.cdecl, importc: "cairo_surface_finish",
|
|
||||||
libcairo.}
|
|
||||||
proc destroy*(surface: PSurface){.cdecl,
|
|
||||||
importc: "cairo_surface_destroy", libcairo.}
|
|
||||||
proc get_reference_count*(surface: PSurface): int32{.cdecl,
|
|
||||||
importc: "cairo_surface_get_reference_count", libcairo.}
|
|
||||||
proc status*(surface: PSurface): TStatus{.cdecl,
|
|
||||||
importc: "cairo_surface_status", libcairo.}
|
|
||||||
proc get_type*(surface: PSurface): TSurfaceType{.cdecl,
|
|
||||||
importc: "cairo_surface_get_type", libcairo.}
|
|
||||||
proc get_content*(surface: PSurface): TContent{.cdecl,
|
|
||||||
importc: "cairo_surface_get_content", libcairo.}
|
|
||||||
proc write_to_png*(surface: PSurface, filename: cstring): TStatus{.
|
|
||||||
cdecl, importc: "cairo_surface_write_to_png", libcairo.}
|
|
||||||
proc write_to_png*(surface: PSurface, write_func: TWriteFunc,
|
|
||||||
closure: pointer): TStatus{.cdecl,
|
|
||||||
importc: "cairo_surface_write_to_png_stream", libcairo.}
|
|
||||||
proc get_user_data*(surface: PSurface, key: PUserDataKey): pointer{.
|
|
||||||
cdecl, importc: "cairo_surface_get_user_data", libcairo.}
|
|
||||||
proc set_user_data*(surface: PSurface, key: PUserDataKey,
|
|
||||||
user_data: pointer, destroy: TDestroyFunc): TStatus{.
|
|
||||||
cdecl, importc: "cairo_surface_set_user_data", libcairo.}
|
|
||||||
proc get_font_options*(surface: PSurface, options: PFontOptions){.cdecl,
|
|
||||||
importc: "cairo_surface_get_font_options", libcairo.}
|
|
||||||
proc flush*(surface: PSurface){.cdecl, importc: "cairo_surface_flush",
|
|
||||||
libcairo.}
|
|
||||||
proc mark_dirty*(surface: PSurface){.cdecl,
|
|
||||||
importc: "cairo_surface_mark_dirty", libcairo.}
|
|
||||||
proc mark_dirty_rectangle*(surface: PSurface, x, y, width, height: int32){.
|
|
||||||
cdecl, importc: "cairo_surface_mark_dirty_rectangle", libcairo.}
|
|
||||||
proc set_device_offset*(surface: PSurface, x_offset, y_offset: float64){.
|
|
||||||
cdecl, importc: "cairo_surface_set_device_offset", libcairo.}
|
|
||||||
proc get_device_offset*(surface: PSurface,
|
|
||||||
x_offset, y_offset: var float64){.cdecl,
|
|
||||||
importc: "cairo_surface_get_device_offset", libcairo.}
|
|
||||||
proc set_fallback_resolution*(surface: PSurface, x_pixels_per_inch,
|
|
||||||
y_pixels_per_inch: float64){.cdecl, importc: "cairo_surface_set_fallback_resolution",
|
|
||||||
libcairo.}
|
|
||||||
#* Image-surface functions
|
|
||||||
proc image_surface_create*(format: TFormat, width, height: int32): PSurface{.
|
|
||||||
cdecl, importc: "cairo_image_surface_create", libcairo.}
|
|
||||||
proc image_surface_create*(data: Pbyte, format: TFormat,
|
|
||||||
width, height, stride: int32): PSurface{.
|
|
||||||
cdecl, importc: "cairo_image_surface_create_for_data", libcairo.}
|
|
||||||
proc get_data*(surface: PSurface): cstring{.cdecl,
|
|
||||||
importc: "cairo_image_surface_get_data", libcairo.}
|
|
||||||
proc get_format*(surface: PSurface): TFormat{.cdecl,
|
|
||||||
importc: "cairo_image_surface_get_format", libcairo.}
|
|
||||||
proc get_width*(surface: PSurface): int32{.cdecl,
|
|
||||||
importc: "cairo_image_surface_get_width", libcairo.}
|
|
||||||
proc get_height*(surface: PSurface): int32{.cdecl,
|
|
||||||
importc: "cairo_image_surface_get_height", libcairo.}
|
|
||||||
proc get_stride*(surface: PSurface): int32{.cdecl,
|
|
||||||
importc: "cairo_image_surface_get_stride", libcairo.}
|
|
||||||
proc image_surface_create_from_png*(filename: cstring): PSurface{.cdecl,
|
|
||||||
importc: "cairo_image_surface_create_from_png", libcairo.}
|
|
||||||
proc image_surface_create_from_png*(read_func: TReadFunc,
|
|
||||||
closure: pointer): PSurface{.cdecl, importc: "cairo_image_surface_create_from_png_stream",
|
|
||||||
libcairo.}
|
|
||||||
#* Pattern creation functions
|
|
||||||
proc pattern_create_rgb*(red, green, blue: float64): PPattern{.cdecl,
|
|
||||||
importc: "cairo_pattern_create_rgb", libcairo.}
|
|
||||||
proc pattern_create_rgba*(red, green, blue, alpha: float64): PPattern{.cdecl,
|
|
||||||
importc: "cairo_pattern_create_rgba", libcairo.}
|
|
||||||
proc pattern_create_for_surface*(surface: PSurface): PPattern{.cdecl,
|
|
||||||
importc: "cairo_pattern_create_for_surface", libcairo.}
|
|
||||||
proc pattern_create_linear*(x0, y0, x1, y1: float64): PPattern{.cdecl,
|
|
||||||
importc: "cairo_pattern_create_linear", libcairo.}
|
|
||||||
proc pattern_create_radial*(cx0, cy0, radius0, cx1, cy1, radius1: float64): PPattern{.
|
|
||||||
cdecl, importc: "cairo_pattern_create_radial", libcairo.}
|
|
||||||
proc reference*(pattern: PPattern): PPattern{.cdecl,
|
|
||||||
importc: "cairo_pattern_reference", libcairo.}
|
|
||||||
proc destroy*(pattern: PPattern){.cdecl,
|
|
||||||
importc: "cairo_pattern_destroy", libcairo.}
|
|
||||||
proc get_reference_count*(pattern: PPattern): int32{.cdecl,
|
|
||||||
importc: "cairo_pattern_get_reference_count", libcairo.}
|
|
||||||
proc status*(pattern: PPattern): TStatus{.cdecl,
|
|
||||||
importc: "cairo_pattern_status", libcairo.}
|
|
||||||
proc get_user_data*(pattern: PPattern, key: PUserDataKey): Pointer{.
|
|
||||||
cdecl, importc: "cairo_pattern_get_user_data", libcairo.}
|
|
||||||
proc set_user_data*(pattern: PPattern, key: PUserDataKey,
|
|
||||||
user_data: Pointer, destroy: TDestroyFunc): TStatus{.
|
|
||||||
cdecl, importc: "cairo_pattern_set_user_data", libcairo.}
|
|
||||||
proc get_type*(pattern: PPattern): TPatternType{.cdecl,
|
|
||||||
importc: "cairo_pattern_get_type", libcairo.}
|
|
||||||
proc add_color_stop_rgb*(pattern: PPattern,
|
|
||||||
offset, red, green, blue: float64){.cdecl,
|
|
||||||
importc: "cairo_pattern_add_color_stop_rgb", libcairo.}
|
|
||||||
proc add_color_stop_rgba*(pattern: PPattern,
|
|
||||||
offset, red, green, blue, alpha: float64){.
|
|
||||||
cdecl, importc: "cairo_pattern_add_color_stop_rgba", libcairo.}
|
|
||||||
proc set_matrix*(pattern: PPattern, matrix: PMatrix){.cdecl,
|
|
||||||
importc: "cairo_pattern_set_matrix", libcairo.}
|
|
||||||
proc get_matrix*(pattern: PPattern, matrix: PMatrix){.cdecl,
|
|
||||||
importc: "cairo_pattern_get_matrix", libcairo.}
|
|
||||||
proc set_extend*(pattern: PPattern, extend: TExtend){.cdecl,
|
|
||||||
importc: "cairo_pattern_set_extend", libcairo.}
|
|
||||||
proc get_extend*(pattern: PPattern): TExtend{.cdecl,
|
|
||||||
importc: "cairo_pattern_get_extend", libcairo.}
|
|
||||||
proc set_filter*(pattern: PPattern, filter: TFilter){.cdecl,
|
|
||||||
importc: "cairo_pattern_set_filter", libcairo.}
|
|
||||||
proc get_filter*(pattern: PPattern): TFilter{.cdecl,
|
|
||||||
importc: "cairo_pattern_get_filter", libcairo.}
|
|
||||||
proc get_rgba*(pattern: PPattern,
|
|
||||||
red, green, blue, alpha: var float64): TStatus{.
|
|
||||||
cdecl, importc: "cairo_pattern_get_rgba", libcairo.}
|
|
||||||
proc get_surface*(pattern: PPattern, surface: PPSurface): TStatus{.
|
|
||||||
cdecl, importc: "cairo_pattern_get_surface", libcairo.}
|
|
||||||
proc get_color_stop_rgba*(pattern: PPattern, index: int32,
|
|
||||||
offset, red, green, blue, alpha: var float64): TStatus{.
|
|
||||||
cdecl, importc: "cairo_pattern_get_color_stop_rgba", libcairo.}
|
|
||||||
proc get_color_stop_count*(pattern: PPattern, count: var int32): TStatus{.
|
|
||||||
cdecl, importc: "cairo_pattern_get_color_stop_count", libcairo.}
|
|
||||||
proc get_linear_points*(pattern: PPattern,
|
|
||||||
x0, y0, x1, y1: var float64): TStatus{.
|
|
||||||
cdecl, importc: "cairo_pattern_get_linear_points", libcairo.}
|
|
||||||
proc get_radial_circles*(pattern: PPattern,
|
|
||||||
x0, y0, r0, x1, y1, r1: var float64): TStatus{.
|
|
||||||
cdecl, importc: "cairo_pattern_get_radial_circles", libcairo.}
|
|
||||||
#* Matrix functions
|
|
||||||
proc init*(matrix: PMatrix, xx, yx, xy, yy, x0, y0: float64){.cdecl,
|
|
||||||
importc: "cairo_matrix_init", libcairo.}
|
|
||||||
proc init_identity*(matrix: PMatrix){.cdecl,
|
|
||||||
importc: "cairo_matrix_init_identity", libcairo.}
|
|
||||||
proc init_translate*(matrix: PMatrix, tx, ty: float64){.cdecl,
|
|
||||||
importc: "cairo_matrix_init_translate", libcairo.}
|
|
||||||
proc init_scale*(matrix: PMatrix, sx, sy: float64){.cdecl,
|
|
||||||
importc: "cairo_matrix_init_scale", libcairo.}
|
|
||||||
proc init_rotate*(matrix: PMatrix, radians: float64){.cdecl,
|
|
||||||
importc: "cairo_matrix_init_rotate", libcairo.}
|
|
||||||
proc translate*(matrix: PMatrix, tx, ty: float64){.cdecl,
|
|
||||||
importc: "cairo_matrix_translate", libcairo.}
|
|
||||||
proc scale*(matrix: PMatrix, sx, sy: float64){.cdecl,
|
|
||||||
importc: "cairo_matrix_scale", libcairo.}
|
|
||||||
proc rotate*(matrix: PMatrix, radians: float64){.cdecl,
|
|
||||||
importc: "cairo_matrix_rotate", libcairo.}
|
|
||||||
proc invert*(matrix: PMatrix): TStatus{.cdecl,
|
|
||||||
importc: "cairo_matrix_invert", libcairo.}
|
|
||||||
proc multiply*(result, a, b: PMatrix){.cdecl,
|
|
||||||
importc: "cairo_matrix_multiply", libcairo.}
|
|
||||||
proc transform_distance*(matrix: PMatrix, dx, dy: var float64){.cdecl,
|
|
||||||
importc: "cairo_matrix_transform_distance", libcairo.}
|
|
||||||
proc transform_point*(matrix: PMatrix, x, y: var float64){.cdecl,
|
|
||||||
importc: "cairo_matrix_transform_point", libcairo.}
|
|
||||||
#* PDF functions
|
|
||||||
proc pdf_surface_create*(filename: cstring,
|
|
||||||
width_in_points, height_in_points: float64): PSurface{.
|
|
||||||
cdecl, importc: "cairo_pdf_surface_create", libcairo.}
|
|
||||||
proc pdf_surface_create_for_stream*(write_func: TWriteFunc, closure: Pointer,
|
|
||||||
width_in_points, height_in_points: float64): PSurface{.
|
|
||||||
cdecl, importc: "cairo_pdf_surface_create_for_stream", libcairo.}
|
|
||||||
proc pdf_surface_set_size*(surface: PSurface,
|
|
||||||
width_in_points, height_in_points: float64){.cdecl,
|
|
||||||
importc: "cairo_pdf_surface_set_size", libcairo.}
|
|
||||||
#* PS functions
|
|
||||||
proc ps_surface_create*(filename: cstring,
|
|
||||||
width_in_points, height_in_points: float64): PSurface{.
|
|
||||||
cdecl, importc: "cairo_ps_surface_create", libcairo.}
|
|
||||||
proc ps_surface_create_for_stream*(write_func: TWriteFunc, closure: Pointer,
|
|
||||||
width_in_points, height_in_points: float64): PSurface{.
|
|
||||||
cdecl, importc: "cairo_ps_surface_create_for_stream", libcairo.}
|
|
||||||
proc ps_surface_set_size*(surface: PSurface,
|
|
||||||
width_in_points, height_in_points: float64){.cdecl,
|
|
||||||
importc: "cairo_ps_surface_set_size", libcairo.}
|
|
||||||
proc ps_surface_dsc_comment*(surface: PSurface, comment: cstring){.cdecl,
|
|
||||||
importc: "cairo_ps_surface_dsc_comment", libcairo.}
|
|
||||||
proc ps_surface_dsc_begin_setup*(surface: PSurface){.cdecl,
|
|
||||||
importc: "cairo_ps_surface_dsc_begin_setup", libcairo.}
|
|
||||||
proc ps_surface_dsc_begin_page_setup*(surface: PSurface){.cdecl,
|
|
||||||
importc: "cairo_ps_surface_dsc_begin_page_setup", libcairo.}
|
|
||||||
#* SVG functions
|
|
||||||
proc svg_surface_create*(filename: cstring,
|
|
||||||
width_in_points, height_in_points: float64): PSurface{.
|
|
||||||
cdecl, importc: "cairo_svg_surface_create", libcairo.}
|
|
||||||
proc svg_surface_create_for_stream*(write_func: TWriteFunc, closure: Pointer,
|
|
||||||
width_in_points, height_in_points: float64): PSurface{.
|
|
||||||
cdecl, importc: "cairo_svg_surface_create_for_stream", libcairo.}
|
|
||||||
proc svg_surface_restrict_to_version*(surface: PSurface, version: TSvgVersion){.
|
|
||||||
cdecl, importc: "cairo_svg_surface_restrict_to_version", libcairo.}
|
|
||||||
#todo: see how translate this
|
|
||||||
#procedure cairo_svg_get_versions(TCairoSvgVersion const **versions,
|
|
||||||
# int *num_versions);
|
|
||||||
proc svg_version_to_string*(version: TSvgVersion): cstring{.cdecl,
|
|
||||||
importc: "cairo_svg_version_to_string", libcairo.}
|
|
||||||
#* Functions to be used while debugging (not intended for use in production code)
|
|
||||||
proc debug_reset_static_data*(){.cdecl,
|
|
||||||
importc: "cairo_debug_reset_static_data",
|
|
||||||
libcairo.}
|
|
||||||
# implementation
|
|
||||||
|
|
||||||
proc version(major, minor, micro: var int32) =
|
|
||||||
var version: int32
|
|
||||||
version = version()
|
|
||||||
major = version div 10000'i32
|
|
||||||
minor = (version mod (major * 10000'i32)) div 100'i32
|
|
||||||
micro = (version mod ((major * 10000'i32) + (minor * 100'i32)))
|
|
||||||
|
|
||||||
proc checkStatus*(s: cairo.TStatus) {.noinline.} =
|
|
||||||
## if ``s != StatusSuccess`` the error is turned into an appropirate Nimrod
|
|
||||||
## exception and raised.
|
|
||||||
case s
|
|
||||||
of StatusSuccess: nil
|
|
||||||
of StatusNoMemory:
|
|
||||||
raise newException(EOutOfMemory, $statusToString(s))
|
|
||||||
of STATUS_READ_ERROR, STATUS_WRITE_ERROR, STATUS_FILE_NOT_FOUND,
|
|
||||||
STATUS_TEMP_FILE_ERROR:
|
|
||||||
raise newException(EIO, $statusToString(s))
|
|
||||||
else:
|
|
||||||
raise newException(EAssertionFailed, $statusToString(s))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
# included by cairo bindings
|
|
||||||
|
|
||||||
when defined(use_pkg_config) or defined(use_pkg_config_static):
|
|
||||||
{.pragma: libcairo, cdecl.}
|
|
||||||
when defined(use_pkg_config_static):
|
|
||||||
{.passl: gorge("pkg-config cairo --libs --static").}
|
|
||||||
else:
|
|
||||||
{.passl: gorge("pkg-config cairo --libs").}
|
|
||||||
else:
|
|
||||||
when defined(windows):
|
|
||||||
const LIB_CAIRO* = "libcairo-2.dll"
|
|
||||||
elif defined(macosx):
|
|
||||||
const LIB_CAIRO* = "libcairo.dylib"
|
|
||||||
else:
|
|
||||||
const LIB_CAIRO* = "libcairo.so(|.2)"
|
|
||||||
{.pragma: libcairo, cdecl, dynlib: LIB_CAIRO.}
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
#
|
|
||||||
# Translation of cairo-ft.h
|
|
||||||
# by Jeffrey Pohlmeyer
|
|
||||||
# updated to version 1.4 by Luiz Américo Pereira Câmara 2007
|
|
||||||
#
|
|
||||||
|
|
||||||
import
|
|
||||||
cairo, freetypeh
|
|
||||||
|
|
||||||
include "cairo_pragma.nim"
|
|
||||||
#todo: properly define FcPattern:
|
|
||||||
#It will require translate FontConfig header
|
|
||||||
|
|
||||||
#*
|
|
||||||
#typedef struct _XftPattern {
|
|
||||||
# int num;
|
|
||||||
# int size;
|
|
||||||
# XftPatternElt *elts;
|
|
||||||
# } XftPattern;
|
|
||||||
# typedef FcPattern XftPattern;
|
|
||||||
#
|
|
||||||
|
|
||||||
type
|
|
||||||
FcPattern* = Pointer
|
|
||||||
PFcPattern* = ptr FcPattern
|
|
||||||
|
|
||||||
proc ft_font_face_create_for_pattern*(pattern: PFcPattern): PFontFace{.libcairo,
|
|
||||||
importc: "cairo_ft_font_face_create_for_pattern".}
|
|
||||||
proc ft_font_options_substitute*(options: PFontOptions, pattern: PFcPattern){.
|
|
||||||
libcairo, importc: "cairo_ft_font_options_substitute".}
|
|
||||||
proc ft_font_face_create_for_ft_face*(face: TFT_Face, load_flags: int32): PFontFace{.libcairo,
|
|
||||||
importc: "cairo_ft_font_face_create_for_ft_face".}
|
|
||||||
proc ft_scaled_font_lock_face*(scaled_font: PScaledFont): TFT_Face{.libcairo,
|
|
||||||
importc: "cairo_ft_scaled_font_lock_face".}
|
|
||||||
proc ft_scaled_font_unlock_face*(scaled_font: PScaledFont){.libcairo,
|
|
||||||
importc: "cairo_ft_scaled_font_unlock_face".}
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
#
|
|
||||||
# Translation of cairo-win32.h version 1.4
|
|
||||||
# by Luiz Américo Pereira Câmara 2007
|
|
||||||
#
|
|
||||||
|
|
||||||
import
|
|
||||||
cairo, windows
|
|
||||||
|
|
||||||
proc win32_surface_create*(hdc: HDC): PSurface{.cdecl,
|
|
||||||
importc: "cairo_win32_surface_create", dynlib: LIB_CAIRO.}
|
|
||||||
proc win32_surface_create_with_ddb*(hdc: HDC, format: TFormat,
|
|
||||||
width, height: int32): PSurface{.cdecl,
|
|
||||||
importc: "cairo_win32_surface_create_with_ddb", dynlib: LIB_CAIRO.}
|
|
||||||
proc win32_surface_create_with_dib*(format: TFormat, width, height: int32): PSurface{.
|
|
||||||
cdecl, importc: "cairo_win32_surface_create_with_dib", dynlib: LIB_CAIRO.}
|
|
||||||
proc win32_surface_get_dc*(surface: PSurface): HDC{.cdecl,
|
|
||||||
importc: "cairo_win32_surface_get_dc", dynlib: LIB_CAIRO.}
|
|
||||||
proc win32_surface_get_image*(surface: PSurface): PSurface{.cdecl,
|
|
||||||
importc: "cairo_win32_surface_get_image", dynlib: LIB_CAIRO.}
|
|
||||||
proc win32_font_face_create_for_logfontw*(logfont: pLOGFONTW): PFontFace{.cdecl,
|
|
||||||
importc: "cairo_win32_font_face_create_for_logfontw", dynlib: LIB_CAIRO.}
|
|
||||||
proc win32_font_face_create_for_hfont*(font: HFONT): PFontFace{.cdecl,
|
|
||||||
importc: "cairo_win32_font_face_create_for_hfont", dynlib: LIB_CAIRO.}
|
|
||||||
proc win32_scaled_font_select_font*(scaled_font: PScaledFont, hdc: HDC): TStatus{.
|
|
||||||
cdecl, importc: "cairo_win32_scaled_font_select_font", dynlib: LIB_CAIRO.}
|
|
||||||
proc win32_scaled_font_done_font*(scaled_font: PScaledFont){.cdecl,
|
|
||||||
importc: "cairo_win32_scaled_font_done_font", dynlib: LIB_CAIRO.}
|
|
||||||
proc win32_scaled_font_get_metrics_factor*(scaled_font: PScaledFont): float64{.
|
|
||||||
cdecl, importc: "cairo_win32_scaled_font_get_metrics_factor",
|
|
||||||
dynlib: LIB_CAIRO.}
|
|
||||||
proc win32_scaled_font_get_logical_to_device*(scaled_font: PScaledFont,
|
|
||||||
logical_to_device: PMatrix){.cdecl, importc: "cairo_win32_scaled_font_get_logical_to_device",
|
|
||||||
dynlib: LIB_CAIRO.}
|
|
||||||
proc win32_scaled_font_get_device_to_logical*(scaled_font: PScaledFont,
|
|
||||||
device_to_logical: PMatrix){.cdecl, importc: "cairo_win32_scaled_font_get_device_to_logical",
|
|
||||||
dynlib: LIB_CAIRO.}
|
|
||||||
# implementation
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
#
|
|
||||||
# Translation of cairo-xlib.h version 1.4
|
|
||||||
# by Jeffrey Pohlmeyer
|
|
||||||
# updated to version 1.4 by Luiz Américo Pereira Câmara 2007
|
|
||||||
#
|
|
||||||
|
|
||||||
import
|
|
||||||
cairo, x, xlib, xrender
|
|
||||||
|
|
||||||
include "cairo_pragma.nim"
|
|
||||||
|
|
||||||
proc xlib_surface_create*(dpy: PDisplay, drawable: TDrawable, visual: PVisual,
|
|
||||||
width, height: int32): PSurface{.cdecl,
|
|
||||||
importc: "cairo_xlib_surface_create", libcairo.}
|
|
||||||
proc xlib_surface_create_for_bitmap*(dpy: PDisplay, bitmap: TPixmap,
|
|
||||||
screen: PScreen, width, height: int32): PSurface{.
|
|
||||||
cdecl, importc: "cairo_xlib_surface_create_for_bitmap", libcairo.}
|
|
||||||
proc xlib_surface_create_with_xrender_format*(dpy: PDisplay,
|
|
||||||
drawable: TDrawable, screen: PScreen, format: PXRenderPictFormat,
|
|
||||||
width, height: int32): PSurface{.cdecl, importc: "cairo_xlib_surface_create_with_xrender_format",
|
|
||||||
libcairo.}
|
|
||||||
proc xlib_surface_get_depth*(surface: PSurface): int32{.cdecl,
|
|
||||||
importc: "cairo_xlib_surface_get_depth", libcairo.}
|
|
||||||
proc xlib_surface_get_display*(surface: PSurface): PDisplay{.cdecl,
|
|
||||||
importc: "cairo_xlib_surface_get_display", libcairo.}
|
|
||||||
proc xlib_surface_get_drawable*(surface: PSurface): TDrawable{.cdecl,
|
|
||||||
importc: "cairo_xlib_surface_get_drawable", libcairo.}
|
|
||||||
proc xlib_surface_get_height*(surface: PSurface): int32{.cdecl,
|
|
||||||
importc: "cairo_xlib_surface_get_height", libcairo.}
|
|
||||||
proc xlib_surface_get_screen*(surface: PSurface): PScreen{.cdecl,
|
|
||||||
importc: "cairo_xlib_surface_get_screen", libcairo.}
|
|
||||||
proc xlib_surface_get_visual*(surface: PSurface): PVisual{.cdecl,
|
|
||||||
importc: "cairo_xlib_surface_get_visual", libcairo.}
|
|
||||||
proc xlib_surface_get_width*(surface: PSurface): int32{.cdecl,
|
|
||||||
importc: "cairo_xlib_surface_get_width", libcairo.}
|
|
||||||
proc xlib_surface_set_size*(surface: PSurface, width, height: int32){.cdecl,
|
|
||||||
importc: "cairo_xlib_surface_set_size", libcairo.}
|
|
||||||
proc xlib_surface_set_drawable*(surface: PSurface, drawable: TDrawable,
|
|
||||||
width, height: int32){.cdecl,
|
|
||||||
importc: "cairo_xlib_surface_set_drawable", libcairo.}
|
|
||||||
# implementation
|
|
||||||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -1,271 +0,0 @@
|
||||||
{.deadCodeElim: on.}
|
|
||||||
import
|
|
||||||
glib2
|
|
||||||
|
|
||||||
when defined(win32):
|
|
||||||
const
|
|
||||||
pixbuflib = "libgdk_pixbuf-2.0-0.dll"
|
|
||||||
elif defined(macosx):
|
|
||||||
const
|
|
||||||
pixbuflib = "libgdk_pixbuf-2.0.0.dylib"
|
|
||||||
# linklib gtk-x11-2.0
|
|
||||||
# linklib gdk-x11-2.0
|
|
||||||
# linklib pango-1.0.0
|
|
||||||
# linklib glib-2.0.0
|
|
||||||
# linklib gobject-2.0.0
|
|
||||||
# linklib gdk_pixbuf-2.0.0
|
|
||||||
# linklib atk-1.0.0
|
|
||||||
else:
|
|
||||||
const
|
|
||||||
pixbuflib = "libgdk_pixbuf-2.0.so"
|
|
||||||
type
|
|
||||||
PPixbuf* = pointer
|
|
||||||
PPixbufAnimation* = pointer
|
|
||||||
PPixbufAnimationIter* = pointer
|
|
||||||
PPixbufAlphaMode* = ptr TPixbufAlphaMode
|
|
||||||
TPixbufAlphaMode* = enum
|
|
||||||
PIXBUF_ALPHA_BILEVEL, PIXBUF_ALPHA_FULL
|
|
||||||
PColorspace* = ptr TColorspace
|
|
||||||
TColorspace* = enum
|
|
||||||
COLORSPACE_RGB
|
|
||||||
TPixbufDestroyNotify* = proc (pixels: Pguchar, data: gpointer){.cdecl.}
|
|
||||||
PPixbufError* = ptr TPixbufError
|
|
||||||
TPixbufError* = enum
|
|
||||||
PIXBUF_ERROR_CORRUPT_IMAGE, PIXBUF_ERROR_INSUFFICIENT_MEMORY,
|
|
||||||
PIXBUF_ERROR_BAD_OPTION, PIXBUF_ERROR_UNKNOWN_TYPE,
|
|
||||||
PIXBUF_ERROR_UNSUPPORTED_OPERATION, PIXBUF_ERROR_FAILED
|
|
||||||
PInterpType* = ptr TInterpType
|
|
||||||
TInterpType* = enum
|
|
||||||
INTERP_NEAREST, INTERP_TILES, INTERP_BILINEAR, INTERP_HYPER
|
|
||||||
|
|
||||||
proc TYPE_PIXBUF*(): GType
|
|
||||||
proc PIXBUF*(anObject: pointer): PPixbuf
|
|
||||||
proc IS_PIXBUF*(anObject: pointer): bool
|
|
||||||
proc TYPE_PIXBUF_ANIMATION*(): GType
|
|
||||||
proc PIXBUF_ANIMATION*(anObject: pointer): PPixbufAnimation
|
|
||||||
proc IS_PIXBUF_ANIMATION*(anObject: pointer): bool
|
|
||||||
proc TYPE_PIXBUF_ANIMATION_ITER*(): GType
|
|
||||||
proc PIXBUF_ANIMATION_ITER*(anObject: pointer): PPixbufAnimationIter
|
|
||||||
proc IS_PIXBUF_ANIMATION_ITER*(anObject: pointer): bool
|
|
||||||
proc PIXBUF_ERROR*(): TGQuark
|
|
||||||
proc pixbuf_error_quark*(): TGQuark{.cdecl, dynlib: pixbuflib,
|
|
||||||
importc: "gdk_pixbuf_error_quark".}
|
|
||||||
proc pixbuf_get_type*(): GType{.cdecl, dynlib: pixbuflib,
|
|
||||||
importc: "gdk_pixbuf_get_type".}
|
|
||||||
when not defined(PIXBUF_DISABLE_DEPRECATED):
|
|
||||||
proc pixbuf_ref*(pixbuf: PPixbuf): PPixbuf{.cdecl, dynlib: pixbuflib,
|
|
||||||
importc: "gdk_pixbuf_ref".}
|
|
||||||
proc pixbuf_unref*(pixbuf: PPixbuf){.cdecl, dynlib: pixbuflib,
|
|
||||||
importc: "gdk_pixbuf_unref".}
|
|
||||||
proc get_colorspace*(pixbuf: PPixbuf): TColorspace{.cdecl,
|
|
||||||
dynlib: pixbuflib, importc: "gdk_pixbuf_get_colorspace".}
|
|
||||||
proc get_n_channels*(pixbuf: PPixbuf): int32{.cdecl, dynlib: pixbuflib,
|
|
||||||
importc: "gdk_pixbuf_get_n_channels".}
|
|
||||||
proc get_has_alpha*(pixbuf: PPixbuf): gboolean{.cdecl, dynlib: pixbuflib,
|
|
||||||
importc: "gdk_pixbuf_get_has_alpha".}
|
|
||||||
proc get_bits_per_sample*(pixbuf: PPixbuf): int32{.cdecl,
|
|
||||||
dynlib: pixbuflib, importc: "gdk_pixbuf_get_bits_per_sample".}
|
|
||||||
proc get_pixels*(pixbuf: PPixbuf): Pguchar{.cdecl, dynlib: pixbuflib,
|
|
||||||
importc: "gdk_pixbuf_get_pixels".}
|
|
||||||
proc get_width*(pixbuf: PPixbuf): int32{.cdecl, dynlib: pixbuflib,
|
|
||||||
importc: "gdk_pixbuf_get_width".}
|
|
||||||
proc get_height*(pixbuf: PPixbuf): int32{.cdecl, dynlib: pixbuflib,
|
|
||||||
importc: "gdk_pixbuf_get_height".}
|
|
||||||
proc get_rowstride*(pixbuf: PPixbuf): int32{.cdecl, dynlib: pixbuflib,
|
|
||||||
importc: "gdk_pixbuf_get_rowstride".}
|
|
||||||
proc pixbuf_new*(colorspace: TColorspace, has_alpha: gboolean,
|
|
||||||
bits_per_sample: int32, width: int32, height: int32): PPixbuf{.
|
|
||||||
cdecl, dynlib: pixbuflib, importc: "gdk_pixbuf_new".}
|
|
||||||
proc copy*(pixbuf: PPixbuf): PPixbuf{.cdecl, dynlib: pixbuflib,
|
|
||||||
importc: "gdk_pixbuf_copy".}
|
|
||||||
proc new_subpixbuf*(src_pixbuf: PPixbuf, src_x: int32, src_y: int32,
|
|
||||||
width: int32, height: int32): PPixbuf{.cdecl,
|
|
||||||
dynlib: pixbuflib, importc: "gdk_pixbuf_new_subpixbuf".}
|
|
||||||
proc pixbuf_new_from_file*(filename: cstring, error: pointer): PPixbuf{.cdecl,
|
|
||||||
dynlib: pixbuflib, importc: "gdk_pixbuf_new_from_file".}
|
|
||||||
proc pixbuf_new_from_data*(data: Pguchar, colorspace: TColorspace,
|
|
||||||
has_alpha: gboolean, bits_per_sample: int32,
|
|
||||||
width: int32, height: int32, rowstride: int32,
|
|
||||||
destroy_fn: TPixbufDestroyNotify,
|
|
||||||
destroy_fn_data: gpointer): PPixbuf{.cdecl,
|
|
||||||
dynlib: pixbuflib, importc: "gdk_pixbuf_new_from_data".}
|
|
||||||
proc pixbuf_new_from_xpm_data*(data: PPchar): PPixbuf{.cdecl, dynlib: pixbuflib,
|
|
||||||
importc: "gdk_pixbuf_new_from_xpm_data".}
|
|
||||||
proc pixbuf_new_from_inline*(data_length: gint, a: var guint8,
|
|
||||||
copy_pixels: gboolean, error: pointer): PPixbuf{.
|
|
||||||
cdecl, dynlib: pixbuflib, importc: "gdk_pixbuf_new_from_inline".}
|
|
||||||
proc pixbuf_new_from_file_at_size*(filename: cstring, width, height: gint,
|
|
||||||
error: pointer): PPixbuf{.cdecl,
|
|
||||||
dynlib: pixbuflib, importc: "gdk_pixbuf_new_from_file_at_size".}
|
|
||||||
proc pixbuf_new_from_file_at_scale*(filename: cstring, width, height: gint,
|
|
||||||
preserve_aspect_ratio: gboolean,
|
|
||||||
error: pointer): PPixbuf{.cdecl,
|
|
||||||
dynlib: pixbuflib, importc: "gdk_pixbuf_new_from_file_at_scale".}
|
|
||||||
proc fill*(pixbuf: PPixbuf, pixel: guint32){.cdecl, dynlib: pixbuflib,
|
|
||||||
importc: "gdk_pixbuf_fill".}
|
|
||||||
proc save*(pixbuf: PPixbuf, filename: cstring, `type`: cstring,
|
|
||||||
error: pointer): gboolean{.cdecl, varargs, dynlib: pixbuflib,
|
|
||||||
importc: "gdk_pixbuf_save".}
|
|
||||||
proc savev*(pixbuf: PPixbuf, filename: cstring, `type`: cstring,
|
|
||||||
option_keys: PPchar, option_values: PPchar, error: pointer): gboolean{.
|
|
||||||
cdecl, dynlib: pixbuflib, importc: "gdk_pixbuf_savev".}
|
|
||||||
proc add_alpha*(pixbuf: PPixbuf, substitute_color: gboolean, r: guchar,
|
|
||||||
g: guchar, b: guchar): PPixbuf{.cdecl, dynlib: pixbuflib,
|
|
||||||
importc: "gdk_pixbuf_add_alpha".}
|
|
||||||
proc copy_area*(src_pixbuf: PPixbuf, src_x: int32, src_y: int32,
|
|
||||||
width: int32, height: int32, dest_pixbuf: PPixbuf,
|
|
||||||
dest_x: int32, dest_y: int32){.cdecl, dynlib: pixbuflib,
|
|
||||||
importc: "gdk_pixbuf_copy_area".}
|
|
||||||
proc saturate_and_pixelate*(src: PPixbuf, dest: PPixbuf,
|
|
||||||
saturation: gfloat, pixelate: gboolean){.
|
|
||||||
cdecl, dynlib: pixbuflib, importc: "gdk_pixbuf_saturate_and_pixelate".}
|
|
||||||
proc scale*(src: PPixbuf, dest: PPixbuf, dest_x: int32, dest_y: int32,
|
|
||||||
dest_width: int32, dest_height: int32, offset_x: float64,
|
|
||||||
offset_y: float64, scale_x: float64, scale_y: float64,
|
|
||||||
interp_type: TInterpType){.cdecl, dynlib: pixbuflib,
|
|
||||||
importc: "gdk_pixbuf_scale".}
|
|
||||||
proc composite*(src: PPixbuf, dest: PPixbuf, dest_x: int32,
|
|
||||||
dest_y: int32, dest_width: int32, dest_height: int32,
|
|
||||||
offset_x: float64, offset_y: float64, scale_x: float64,
|
|
||||||
scale_y: float64, interp_type: TInterpType,
|
|
||||||
overall_alpha: int32){.cdecl, dynlib: pixbuflib,
|
|
||||||
importc: "gdk_pixbuf_composite".}
|
|
||||||
proc composite_color*(src: PPixbuf, dest: PPixbuf, dest_x: int32,
|
|
||||||
dest_y: int32, dest_width: int32,
|
|
||||||
dest_height: int32, offset_x: float64,
|
|
||||||
offset_y: float64, scale_x: float64,
|
|
||||||
scale_y: float64, interp_type: TInterpType,
|
|
||||||
overall_alpha: int32, check_x: int32,
|
|
||||||
check_y: int32, check_size: int32, color1: guint32,
|
|
||||||
color2: guint32){.cdecl, dynlib: pixbuflib,
|
|
||||||
importc: "gdk_pixbuf_composite_color".}
|
|
||||||
proc scale_simple*(src: PPixbuf, dest_width: int32, dest_height: int32,
|
|
||||||
interp_type: TInterpType): PPixbuf{.cdecl,
|
|
||||||
dynlib: pixbuflib, importc: "gdk_pixbuf_scale_simple".}
|
|
||||||
proc composite_color_simple*(src: PPixbuf, dest_width: int32,
|
|
||||||
dest_height: int32,
|
|
||||||
interp_type: TInterpType,
|
|
||||||
overall_alpha: int32, check_size: int32,
|
|
||||||
color1: guint32, color2: guint32): PPixbuf{.
|
|
||||||
cdecl, dynlib: pixbuflib, importc: "gdk_pixbuf_composite_color_simple".}
|
|
||||||
proc pixbuf_animation_get_type*(): GType{.cdecl, dynlib: pixbuflib,
|
|
||||||
importc: "gdk_pixbuf_animation_get_type".}
|
|
||||||
proc pixbuf_animation_new_from_file*(filename: cstring, error: pointer): PPixbufAnimation{.
|
|
||||||
cdecl, dynlib: pixbuflib, importc: "gdk_pixbuf_animation_new_from_file".}
|
|
||||||
when not defined(PIXBUF_DISABLE_DEPRECATED):
|
|
||||||
proc pixbuf_animation_ref*(animation: PPixbufAnimation): PPixbufAnimation{.
|
|
||||||
cdecl, dynlib: pixbuflib, importc: "gdk_pixbuf_animation_ref".}
|
|
||||||
proc pixbuf_animation_unref*(animation: PPixbufAnimation){.cdecl,
|
|
||||||
dynlib: pixbuflib, importc: "gdk_pixbuf_animation_unref".}
|
|
||||||
proc get_width*(animation: PPixbufAnimation): int32{.cdecl,
|
|
||||||
dynlib: pixbuflib, importc: "gdk_pixbuf_animation_get_width".}
|
|
||||||
proc get_height*(animation: PPixbufAnimation): int32{.cdecl,
|
|
||||||
dynlib: pixbuflib, importc: "gdk_pixbuf_animation_get_height".}
|
|
||||||
proc is_static_image*(animation: PPixbufAnimation): gboolean{.
|
|
||||||
cdecl, dynlib: pixbuflib, importc: "gdk_pixbuf_animation_is_static_image".}
|
|
||||||
proc get_static_image*(animation: PPixbufAnimation): PPixbuf{.
|
|
||||||
cdecl, dynlib: pixbuflib, importc: "gdk_pixbuf_animation_get_static_image".}
|
|
||||||
proc get_iter*(animation: PPixbufAnimation, e: var TGTimeVal): PPixbufAnimationIter{.
|
|
||||||
cdecl, dynlib: pixbuflib, importc: "gdk_pixbuf_animation_get_iter".}
|
|
||||||
proc pixbuf_animation_iter_get_type*(): GType{.cdecl, dynlib: pixbuflib,
|
|
||||||
importc: "gdk_pixbuf_animation_iter_get_type".}
|
|
||||||
proc iter_get_delay_time*(iter: PPixbufAnimationIter): int32{.
|
|
||||||
cdecl, dynlib: pixbuflib,
|
|
||||||
importc: "gdk_pixbuf_animation_iter_get_delay_time".}
|
|
||||||
proc iter_get_pixbuf*(iter: PPixbufAnimationIter): PPixbuf{.
|
|
||||||
cdecl, dynlib: pixbuflib, importc: "gdk_pixbuf_animation_iter_get_pixbuf".}
|
|
||||||
proc pixbuf_animation_iter_on_currently_loading_frame*(
|
|
||||||
iter: PPixbufAnimationIter): gboolean{.cdecl, dynlib: pixbuflib,
|
|
||||||
importc: "gdk_pixbuf_animation_iter_on_currently_loading_frame".}
|
|
||||||
proc iter_advance*(iter: PPixbufAnimationIter, e: var TGTimeVal): gboolean{.
|
|
||||||
cdecl, dynlib: pixbuflib, importc: "gdk_pixbuf_animation_iter_advance".}
|
|
||||||
proc get_option*(pixbuf: PPixbuf, key: cstring): cstring{.cdecl,
|
|
||||||
dynlib: pixbuflib, importc: "gdk_pixbuf_get_option".}
|
|
||||||
type
|
|
||||||
PPixbufLoader* = ptr TPixbufLoader
|
|
||||||
TPixbufLoader*{.final, pure.} = object
|
|
||||||
parent_instance*: TGObject
|
|
||||||
priv*: gpointer
|
|
||||||
|
|
||||||
PPixbufLoaderClass* = ptr TPixbufLoaderClass
|
|
||||||
TPixbufLoaderClass*{.final, pure.} = object
|
|
||||||
parent_class*: TGObjectClass
|
|
||||||
area_prepared*: proc (loader: PPixbufLoader){.cdecl.}
|
|
||||||
area_updated*: proc (loader: PPixbufLoader, x: int32, y: int32,
|
|
||||||
width: int32, height: int32){.cdecl.}
|
|
||||||
closed*: proc (loader: PPixbufLoader){.cdecl.}
|
|
||||||
|
|
||||||
|
|
||||||
proc TYPE_PIXBUF_LOADER*(): GType
|
|
||||||
proc PIXBUF_LOADER*(obj: pointer): PPixbufLoader
|
|
||||||
proc PIXBUF_LOADER_CLASS*(klass: pointer): PPixbufLoaderClass
|
|
||||||
proc IS_PIXBUF_LOADER*(obj: pointer): bool
|
|
||||||
proc IS_PIXBUF_LOADER_CLASS*(klass: pointer): bool
|
|
||||||
proc PIXBUF_LOADER_GET_CLASS*(obj: pointer): PPixbufLoaderClass
|
|
||||||
proc pixbuf_loader_get_type*(): GType{.cdecl, dynlib: pixbuflib,
|
|
||||||
importc: "gdk_pixbuf_loader_get_type".}
|
|
||||||
proc pixbuf_loader_new*(): PPixbufLoader{.cdecl, dynlib: pixbuflib,
|
|
||||||
importc: "gdk_pixbuf_loader_new".}
|
|
||||||
proc pixbuf_loader_new*(image_type: cstring, error: pointer): PPixbufLoader{.
|
|
||||||
cdecl, dynlib: pixbuflib, importc: "gdk_pixbuf_loader_new_with_type".}
|
|
||||||
proc write*(loader: PPixbufLoader, buf: Pguchar, count: gsize,
|
|
||||||
error: pointer): gboolean{.cdecl, dynlib: pixbuflib,
|
|
||||||
importc: "gdk_pixbuf_loader_write".}
|
|
||||||
proc get_pixbuf*(loader: PPixbufLoader): PPixbuf{.cdecl,
|
|
||||||
dynlib: pixbuflib, importc: "gdk_pixbuf_loader_get_pixbuf".}
|
|
||||||
proc get_animation*(loader: PPixbufLoader): PPixbufAnimation{.
|
|
||||||
cdecl, dynlib: pixbuflib, importc: "gdk_pixbuf_loader_get_animation".}
|
|
||||||
proc close*(loader: PPixbufLoader, error: pointer): gboolean{.
|
|
||||||
cdecl, dynlib: pixbuflib, importc: "gdk_pixbuf_loader_close".}
|
|
||||||
proc TYPE_PIXBUF_LOADER*(): GType =
|
|
||||||
result = pixbuf_loader_get_type()
|
|
||||||
|
|
||||||
proc PIXBUF_LOADER*(obj: pointer): PPixbufLoader =
|
|
||||||
result = cast[PPixbufLoader](G_TYPE_CHECK_INSTANCE_CAST(obj,
|
|
||||||
TYPE_PIXBUF_LOADER()))
|
|
||||||
|
|
||||||
proc PIXBUF_LOADER_CLASS*(klass: pointer): PPixbufLoaderClass =
|
|
||||||
result = cast[PPixbufLoaderClass](G_TYPE_CHECK_CLASS_CAST(klass,
|
|
||||||
TYPE_PIXBUF_LOADER()))
|
|
||||||
|
|
||||||
proc IS_PIXBUF_LOADER*(obj: pointer): bool =
|
|
||||||
result = G_TYPE_CHECK_INSTANCE_TYPE(obj, TYPE_PIXBUF_LOADER())
|
|
||||||
|
|
||||||
proc IS_PIXBUF_LOADER_CLASS*(klass: pointer): bool =
|
|
||||||
result = G_TYPE_CHECK_CLASS_TYPE(klass, TYPE_PIXBUF_LOADER())
|
|
||||||
|
|
||||||
proc PIXBUF_LOADER_GET_CLASS*(obj: pointer): PPixbufLoaderClass =
|
|
||||||
result = cast[PPixbufLoaderClass](G_TYPE_INSTANCE_GET_CLASS(obj,
|
|
||||||
TYPE_PIXBUF_LOADER()))
|
|
||||||
|
|
||||||
proc TYPE_PIXBUF*(): GType =
|
|
||||||
result = pixbuf_get_type()
|
|
||||||
|
|
||||||
proc PIXBUF*(anObject: pointer): PPixbuf =
|
|
||||||
result = cast[PPixbuf](G_TYPE_CHECK_INSTANCE_CAST(anObject, TYPE_PIXBUF()))
|
|
||||||
|
|
||||||
proc IS_PIXBUF*(anObject: pointer): bool =
|
|
||||||
result = G_TYPE_CHECK_INSTANCE_TYPE(anObject, TYPE_PIXBUF())
|
|
||||||
|
|
||||||
proc TYPE_PIXBUF_ANIMATION*(): GType =
|
|
||||||
result = pixbuf_animation_get_type()
|
|
||||||
|
|
||||||
proc PIXBUF_ANIMATION*(anObject: pointer): PPixbufAnimation =
|
|
||||||
result = cast[PPixbufAnimation](G_TYPE_CHECK_INSTANCE_CAST(anObject,
|
|
||||||
TYPE_PIXBUF_ANIMATION()))
|
|
||||||
|
|
||||||
proc IS_PIXBUF_ANIMATION*(anObject: pointer): bool =
|
|
||||||
result = G_TYPE_CHECK_INSTANCE_TYPE(anObject, TYPE_PIXBUF_ANIMATION())
|
|
||||||
|
|
||||||
proc TYPE_PIXBUF_ANIMATION_ITER*(): GType =
|
|
||||||
result = pixbuf_animation_iter_get_type()
|
|
||||||
|
|
||||||
proc PIXBUF_ANIMATION_ITER*(anObject: pointer): PPixbufAnimationIter =
|
|
||||||
result = cast[PPixbufAnimationIter](G_TYPE_CHECK_INSTANCE_CAST(anObject,
|
|
||||||
TYPE_PIXBUF_ANIMATION_ITER()))
|
|
||||||
|
|
||||||
proc IS_PIXBUF_ANIMATION_ITER*(anObject: pointer): bool =
|
|
||||||
result = G_TYPE_CHECK_INSTANCE_TYPE(anObject, TYPE_PIXBUF_ANIMATION_ITER())
|
|
||||||
|
|
||||||
proc PIXBUF_ERROR*(): TGQuark =
|
|
||||||
result = pixbuf_error_quark()
|
|
||||||
|
|
@ -1,554 +0,0 @@
|
||||||
{.deadCodeElim: on.}
|
|
||||||
import
|
|
||||||
Glib2, gdk2
|
|
||||||
|
|
||||||
when defined(WIN32):
|
|
||||||
const
|
|
||||||
GLExtLib = "libgdkglext-win32-1.0-0.dll"
|
|
||||||
elif defined(macosx):
|
|
||||||
const
|
|
||||||
GLExtLib = "libgdkglext-x11-1.0.dylib"
|
|
||||||
else:
|
|
||||||
const
|
|
||||||
GLExtLib = "libgdkglext-x11-1.0.so"
|
|
||||||
type
|
|
||||||
TGLConfigAttrib* = int32
|
|
||||||
TGLConfigCaveat* = int32
|
|
||||||
TGLVisualType* = int32
|
|
||||||
TGLTransparentType* = int32
|
|
||||||
TGLDrawableTypeMask* = int32
|
|
||||||
TGLRenderTypeMask* = int32
|
|
||||||
TGLBufferMask* = int32
|
|
||||||
TGLConfigError* = int32
|
|
||||||
TGLRenderType* = int32
|
|
||||||
TGLDrawableAttrib* = int32
|
|
||||||
TGLPbufferAttrib* = int32
|
|
||||||
TGLEventMask* = int32
|
|
||||||
TGLEventType* = int32
|
|
||||||
TGLDrawableType* = int32
|
|
||||||
TGLProc* = Pointer
|
|
||||||
PGLConfig* = ptr TGLConfig
|
|
||||||
PGLContext* = ptr TGLContext
|
|
||||||
PGLDrawable* = ptr TGLDrawable
|
|
||||||
PGLPixmap* = ptr TGLPixmap
|
|
||||||
PGLWindow* = ptr TGLWindow
|
|
||||||
TGLConfig* = object of TGObject
|
|
||||||
layer_plane*: gint
|
|
||||||
n_aux_buffers*: gint
|
|
||||||
n_sample_buffers*: gint
|
|
||||||
flag0*: int16
|
|
||||||
|
|
||||||
PGLConfigClass* = ptr TGLConfigClass
|
|
||||||
TGLConfigClass* = object of TGObjectClass
|
|
||||||
TGLContext* = object of TGObject
|
|
||||||
PGLContextClass* = ptr TGLContextClass
|
|
||||||
TGLContextClass* = object of TGObjectClass
|
|
||||||
TGLDrawable* = object of TGObject
|
|
||||||
PGLDrawableClass* = ptr TGLDrawableClass
|
|
||||||
TGLDrawableClass* = object of TGTypeInterface
|
|
||||||
create_new_context*: proc (gldrawable: PGLDrawable, share_list: PGLContext,
|
|
||||||
direct: gboolean, render_type: int32): PGLContext{.
|
|
||||||
cdecl.}
|
|
||||||
make_context_current*: proc (draw: PGLDrawable, a_read: PGLDrawable,
|
|
||||||
glcontext: PGLContext): gboolean{.cdecl.}
|
|
||||||
is_double_buffered*: proc (gldrawable: PGLDrawable): gboolean{.cdecl.}
|
|
||||||
swap_buffers*: proc (gldrawable: PGLDrawable){.cdecl.}
|
|
||||||
wait_gl*: proc (gldrawable: PGLDrawable){.cdecl.}
|
|
||||||
wait_gdk*: proc (gldrawable: PGLDrawable){.cdecl.}
|
|
||||||
gl_begin*: proc (draw: PGLDrawable, a_read: PGLDrawable,
|
|
||||||
glcontext: PGLContext): gboolean{.cdecl.}
|
|
||||||
gl_end*: proc (gldrawable: PGLDrawable){.cdecl.}
|
|
||||||
get_gl_config*: proc (gldrawable: PGLDrawable): PGLConfig{.cdecl.}
|
|
||||||
get_size*: proc (gldrawable: PGLDrawable, width, height: PGInt){.cdecl.}
|
|
||||||
|
|
||||||
TGLPixmap* = object of TGObject
|
|
||||||
drawable*: PDrawable
|
|
||||||
|
|
||||||
PGLPixmapClass* = ptr TGLPixmapClass
|
|
||||||
TGLPixmapClass* = object of TGObjectClass
|
|
||||||
TGLWindow* = object of TGObject
|
|
||||||
drawable*: PDrawable
|
|
||||||
|
|
||||||
PGLWindowClass* = ptr TGLWindowClass
|
|
||||||
TGLWindowClass* = object of TGObjectClass
|
|
||||||
|
|
||||||
const
|
|
||||||
HEADER_GDKGLEXT_MAJOR_VERSION* = 1
|
|
||||||
HEADER_GDKGLEXT_MINOR_VERSION* = 0
|
|
||||||
HEADER_GDKGLEXT_MICRO_VERSION* = 6
|
|
||||||
HEADER_GDKGLEXT_INTERFACE_AGE* = 4
|
|
||||||
HEADER_GDKGLEXT_BINARY_AGE* = 6
|
|
||||||
|
|
||||||
proc HEADER_GDKGLEXT_CHECK_VERSION*(major, minor, micro: guint): bool
|
|
||||||
var
|
|
||||||
glext_major_version*{.importc, dynlib: GLExtLib.}: guint
|
|
||||||
glext_minor_version*{.importc, dynlib: GLExtLib.}: guint
|
|
||||||
glext_micro_version*{.importc, dynlib: GLExtLib.}: guint
|
|
||||||
glext_interface_age*{.importc, dynlib: GLExtLib.}: guint
|
|
||||||
glext_binary_age*{.importc, dynlib: GLExtLib.}: guint
|
|
||||||
|
|
||||||
const
|
|
||||||
GL_SUCCESS* = 0
|
|
||||||
GL_ATTRIB_LIST_NONE* = 0
|
|
||||||
GL_USE_GL* = 1
|
|
||||||
GL_BUFFER_SIZE* = 2
|
|
||||||
GL_LEVEL* = 3
|
|
||||||
GL_RGBA* = 4
|
|
||||||
GL_DOUBLEBUFFER* = 5
|
|
||||||
GL_STEREO* = 6
|
|
||||||
GL_AUX_BUFFERS* = 7
|
|
||||||
GL_RED_SIZE* = 8
|
|
||||||
GL_GREEN_SIZE* = 9
|
|
||||||
GL_BLUE_SIZE* = 10
|
|
||||||
GL_ALPHA_SIZE* = 11
|
|
||||||
GL_DEPTH_SIZE* = 12
|
|
||||||
GL_STENCIL_SIZE* = 13
|
|
||||||
GL_ACCUM_RED_SIZE* = 14
|
|
||||||
GL_ACCUM_GREEN_SIZE* = 15
|
|
||||||
GL_ACCUM_BLUE_SIZE* = 16
|
|
||||||
GL_ACCUM_ALPHA_SIZE* = 17
|
|
||||||
GL_CONFIG_CAVEAT* = 0x00000020
|
|
||||||
GL_X_VISUAL_TYPE* = 0x00000022
|
|
||||||
GL_TRANSPARENT_TYPE* = 0x00000023
|
|
||||||
GL_TRANSPARENT_INDEX_VALUE* = 0x00000024
|
|
||||||
GL_TRANSPARENT_RED_VALUE* = 0x00000025
|
|
||||||
GL_TRANSPARENT_GREEN_VALUE* = 0x00000026
|
|
||||||
GL_TRANSPARENT_BLUE_VALUE* = 0x00000027
|
|
||||||
GL_TRANSPARENT_ALPHA_VALUE* = 0x00000028
|
|
||||||
GL_DRAWABLE_TYPE* = 0x00008010
|
|
||||||
GL_RENDER_TYPE* = 0x00008011
|
|
||||||
GL_X_RENDERABLE* = 0x00008012
|
|
||||||
GL_FBCONFIG_ID* = 0x00008013
|
|
||||||
GL_MAX_PBUFFER_WIDTH* = 0x00008016
|
|
||||||
GL_MAX_PBUFFER_HEIGHT* = 0x00008017
|
|
||||||
GL_MAX_PBUFFER_PIXELS* = 0x00008018
|
|
||||||
GL_VISUAL_ID* = 0x0000800B
|
|
||||||
GL_SCREEN* = 0x0000800C
|
|
||||||
GL_SAMPLE_BUFFERS* = 100000
|
|
||||||
GL_SAMPLES* = 100001
|
|
||||||
GL_DONT_CARE* = 0xFFFFFFFF
|
|
||||||
GL_NONE* = 0x00008000
|
|
||||||
GL_CONFIG_CAVEAT_DONT_CARE* = 0xFFFFFFFF
|
|
||||||
GL_CONFIG_CAVEAT_NONE* = 0x00008000
|
|
||||||
GL_SLOW_CONFIG* = 0x00008001
|
|
||||||
GL_NON_CONFORMANT_CONFIG* = 0x0000800D
|
|
||||||
GL_VISUAL_TYPE_DONT_CARE* = 0xFFFFFFFF
|
|
||||||
GL_TRUE_COLOR* = 0x00008002
|
|
||||||
GL_DIRECT_COLOR* = 0x00008003
|
|
||||||
GL_PSEUDO_COLOR* = 0x00008004
|
|
||||||
GL_STATIC_COLOR* = 0x00008005
|
|
||||||
GL_GRAY_SCALE* = 0x00008006
|
|
||||||
GL_STATIC_GRAY* = 0x00008007
|
|
||||||
GL_TRANSPARENT_NONE* = 0x00008000
|
|
||||||
GL_TRANSPARENT_RGB* = 0x00008008
|
|
||||||
GL_TRANSPARENT_INDEX* = 0x00008009
|
|
||||||
GL_WINDOW_BIT* = 1 shl 0
|
|
||||||
GL_PIXMAP_BIT* = 1 shl 1
|
|
||||||
GL_PBUFFER_BIT* = 1 shl 2
|
|
||||||
GL_RGBA_BIT* = 1 shl 0
|
|
||||||
GL_COLOR_INDEX_BIT* = 1 shl 1
|
|
||||||
GL_FRONT_LEFT_BUFFER_BIT* = 1 shl 0
|
|
||||||
GL_FRONT_RIGHT_BUFFER_BIT* = 1 shl 1
|
|
||||||
GL_BACK_LEFT_BUFFER_BIT* = 1 shl 2
|
|
||||||
GL_BACK_RIGHT_BUFFER_BIT* = 1 shl 3
|
|
||||||
GL_AUX_BUFFERS_BIT* = 1 shl 4
|
|
||||||
GL_DEPTH_BUFFER_BIT* = 1 shl 5
|
|
||||||
GL_STENCIL_BUFFER_BIT* = 1 shl 6
|
|
||||||
GL_ACCUM_BUFFER_BIT* = 1 shl 7
|
|
||||||
GL_BAD_SCREEN* = 1
|
|
||||||
GL_BAD_ATTRIBUTE* = 2
|
|
||||||
GL_NO_EXTENSION* = 3
|
|
||||||
GL_BAD_VISUAL* = 4
|
|
||||||
GL_BAD_CONTEXT* = 5
|
|
||||||
GL_BAD_VALUE* = 6
|
|
||||||
GL_BAD_ENUM* = 7
|
|
||||||
GL_RGBA_TYPE* = 0x00008014
|
|
||||||
GL_COLOR_INDEX_TYPE* = 0x00008015
|
|
||||||
GL_PRESERVED_CONTENTS* = 0x0000801B
|
|
||||||
GL_LARGEST_PBUFFER* = 0x0000801C
|
|
||||||
GL_WIDTH* = 0x0000801D
|
|
||||||
GL_HEIGHT* = 0x0000801E
|
|
||||||
GL_EVENT_MASK* = 0x0000801F
|
|
||||||
GL_PBUFFER_PRESERVED_CONTENTS* = 0x0000801B
|
|
||||||
GL_PBUFFER_LARGEST_PBUFFER* = 0x0000801C
|
|
||||||
GL_PBUFFER_HEIGHT* = 0x00008040
|
|
||||||
GL_PBUFFER_WIDTH* = 0x00008041
|
|
||||||
GL_PBUFFER_CLOBBER_MASK* = 1 shl 27
|
|
||||||
GL_DAMAGED* = 0x00008020
|
|
||||||
GL_SAVED* = 0x00008021
|
|
||||||
GL_WINDOW_VALUE* = 0x00008022
|
|
||||||
GL_PBUFFER* = 0x00008023
|
|
||||||
|
|
||||||
proc gl_config_attrib_get_type*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_config_attrib_get_type".}
|
|
||||||
proc TYPE_GL_CONFIG_ATTRIB*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_config_attrib_get_type".}
|
|
||||||
proc gl_config_caveat_get_type*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_config_caveat_get_type".}
|
|
||||||
proc TYPE_GL_CONFIG_CAVEAT*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_config_caveat_get_type".}
|
|
||||||
proc gl_visual_type_get_type*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_visual_type_get_type".}
|
|
||||||
proc TYPE_GL_VISUAL_TYPE*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_visual_type_get_type".}
|
|
||||||
proc gl_transparent_type_get_type*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_transparent_type_get_type".}
|
|
||||||
proc TYPE_GL_TRANSPARENT_TYPE*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_transparent_type_get_type".}
|
|
||||||
proc gl_drawable_type_mask_get_type*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_drawable_type_mask_get_type".}
|
|
||||||
proc TYPE_GL_DRAWABLE_TYPE_MASK*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_drawable_type_mask_get_type".}
|
|
||||||
proc gl_render_type_mask_get_type*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_render_type_mask_get_type".}
|
|
||||||
proc TYPE_GL_RENDER_TYPE_MASK*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_render_type_mask_get_type".}
|
|
||||||
proc gl_buffer_mask_get_type*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_buffer_mask_get_type".}
|
|
||||||
proc TYPE_GL_BUFFER_MASK*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_buffer_mask_get_type".}
|
|
||||||
proc gl_config_error_get_type*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_config_error_get_type".}
|
|
||||||
proc TYPE_GL_CONFIG_ERROR*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_config_error_get_type".}
|
|
||||||
proc gl_render_type_get_type*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_render_type_get_type".}
|
|
||||||
proc TYPE_GL_RENDER_TYPE*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_render_type_get_type".}
|
|
||||||
proc gl_drawable_attrib_get_type*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_drawable_attrib_get_type".}
|
|
||||||
proc TYPE_GL_DRAWABLE_ATTRIB*(): GType{.cdecl, dynlib: GLExtLib, importc: "gdk_gl_drawable_attrib_get_type".}
|
|
||||||
proc gl_pbuffer_attrib_get_type*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_pbuffer_attrib_get_type".}
|
|
||||||
proc TYPE_GL_PBUFFER_ATTRIB*(): GType{.cdecl, dynlib: GLExtLib, importc: "gdk_gl_pbuffer_attrib_get_type".}
|
|
||||||
proc gl_event_mask_get_type*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_event_mask_get_type".}
|
|
||||||
proc TYPE_GL_EVENT_MASK*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_event_mask_get_type".}
|
|
||||||
proc gl_event_type_get_type*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_event_type_get_type".}
|
|
||||||
proc TYPE_GL_EVENT_TYPE*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_event_type_get_type".}
|
|
||||||
proc gl_drawable_type_get_type*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_drawable_type_get_type".}
|
|
||||||
proc TYPE_GL_DRAWABLE_TYPE*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_drawable_type_get_type".}
|
|
||||||
proc gl_config_mode_get_type*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_config_mode_get_type".}
|
|
||||||
proc TYPE_GL_CONFIG_MODE*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_config_mode_get_type".}
|
|
||||||
proc gl_parse_args*(argc: var int32, argv: ptr cstringArray): gboolean{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gdk_gl_parse_args".}
|
|
||||||
proc gl_init_check*(argc: var int32, argv: ptr cstringArray): gboolean{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gdk_gl_init_check".}
|
|
||||||
proc gl_init*(argc: var int32, argv: ptr cstringArray){.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_init".}
|
|
||||||
proc gl_query_gl_extension*(extension: cstring): gboolean{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gdk_gl_query_gl_extension".}
|
|
||||||
proc gl_get_proc_address*(proc_name: cstring): TGLProc{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_get_proc_address".}
|
|
||||||
const
|
|
||||||
bm_TGdkGLConfig_is_rgba* = 1 shl 0
|
|
||||||
bp_TGdkGLConfig_is_rgba* = 0
|
|
||||||
bm_TGdkGLConfig_is_double_buffered* = 1 shl 1
|
|
||||||
bp_TGdkGLConfig_is_double_buffered* = 1
|
|
||||||
bm_TGdkGLConfig_as_single_mode* = 1 shl 2
|
|
||||||
bp_TGdkGLConfig_as_single_mode* = 2
|
|
||||||
bm_TGdkGLConfig_is_stereo* = 1 shl 3
|
|
||||||
bp_TGdkGLConfig_is_stereo* = 3
|
|
||||||
bm_TGdkGLConfig_has_alpha* = 1 shl 4
|
|
||||||
bp_TGdkGLConfig_has_alpha* = 4
|
|
||||||
bm_TGdkGLConfig_has_depth_buffer* = 1 shl 5
|
|
||||||
bp_TGdkGLConfig_has_depth_buffer* = 5
|
|
||||||
bm_TGdkGLConfig_has_stencil_buffer* = 1 shl 6
|
|
||||||
bp_TGdkGLConfig_has_stencil_buffer* = 6
|
|
||||||
bm_TGdkGLConfig_has_accum_buffer* = 1 shl 7
|
|
||||||
bp_TGdkGLConfig_has_accum_buffer* = 7
|
|
||||||
|
|
||||||
const
|
|
||||||
GL_MODE_RGB* = 0
|
|
||||||
GL_MODE_RGBA* = 0
|
|
||||||
GL_MODE_INDEX* = 1 shl 0
|
|
||||||
GL_MODE_SINGLE* = 0
|
|
||||||
GL_MODE_DOUBLE* = 1 shl 1
|
|
||||||
GL_MODE_STEREO* = 1 shl 2
|
|
||||||
GL_MODE_ALPHA* = 1 shl 3
|
|
||||||
GL_MODE_DEPTH* = 1 shl 4
|
|
||||||
GL_MODE_STENCIL* = 1 shl 5
|
|
||||||
GL_MODE_ACCUM* = 1 shl 6
|
|
||||||
GL_MODE_MULTISAMPLE* = 1 shl 7
|
|
||||||
|
|
||||||
type
|
|
||||||
TGLConfigMode* = int32
|
|
||||||
PGLConfigMode* = ptr TGLConfigMode
|
|
||||||
|
|
||||||
proc TYPE_GL_CONFIG*(): GType
|
|
||||||
proc GL_CONFIG*(anObject: Pointer): PGLConfig
|
|
||||||
proc GL_CONFIG_CLASS*(klass: Pointer): PGLConfigClass
|
|
||||||
proc IS_GL_CONFIG*(anObject: Pointer): bool
|
|
||||||
proc IS_GL_CONFIG_CLASS*(klass: Pointer): bool
|
|
||||||
proc GL_CONFIG_GET_CLASS*(obj: Pointer): PGLConfigClass
|
|
||||||
proc gl_config_get_type*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_config_get_type".}
|
|
||||||
proc get_screen*(glconfig: PGLConfig): PScreen{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gdk_gl_config_get_screen".}
|
|
||||||
proc get_attrib*(glconfig: PGLConfig, attribute: int, value: var cint): gboolean{.
|
|
||||||
cdecl, dynlib: GLExtLib, importc: "gdk_gl_config_get_attrib".}
|
|
||||||
proc get_colormap*(glconfig: PGLConfig): PColormap{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gdk_gl_config_get_colormap".}
|
|
||||||
proc get_visual*(glconfig: PGLConfig): PVisual{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gdk_gl_config_get_visual".}
|
|
||||||
proc get_depth*(glconfig: PGLConfig): gint{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_config_get_depth".}
|
|
||||||
proc get_layer_plane*(glconfig: PGLConfig): gint{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gdk_gl_config_get_layer_plane".}
|
|
||||||
proc get_n_aux_buffers*(glconfig: PGLConfig): gint{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gdk_gl_config_get_n_aux_buffers".}
|
|
||||||
proc get_n_sample_buffers*(glconfig: PGLConfig): gint{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gdk_gl_config_get_n_sample_buffers".}
|
|
||||||
proc is_rgba*(glconfig: PGLConfig): gboolean{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_config_is_rgba".}
|
|
||||||
proc is_double_buffered*(glconfig: PGLConfig): gboolean{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gdk_gl_config_is_double_buffered".}
|
|
||||||
proc is_stereo*(glconfig: PGLConfig): gboolean{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gdk_gl_config_is_stereo".}
|
|
||||||
proc has_alpha*(glconfig: PGLConfig): gboolean{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gdk_gl_config_has_alpha".}
|
|
||||||
proc has_depth_buffer*(glconfig: PGLConfig): gboolean{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gdk_gl_config_has_depth_buffer".}
|
|
||||||
proc has_stencil_buffer*(glconfig: PGLConfig): gboolean{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gdk_gl_config_has_stencil_buffer".}
|
|
||||||
proc has_accum_buffer*(glconfig: PGLConfig): gboolean{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gdk_gl_config_has_accum_buffer".}
|
|
||||||
proc TYPE_GL_CONTEXT*(): GType
|
|
||||||
proc GL_CONTEXT*(anObject: Pointer): PGLContext
|
|
||||||
proc GL_CONTEXT_CLASS*(klass: Pointer): PGLContextClass
|
|
||||||
proc IS_GL_CONTEXT*(anObject: Pointer): bool
|
|
||||||
proc IS_GL_CONTEXT_CLASS*(klass: Pointer): bool
|
|
||||||
proc GL_CONTEXT_GET_CLASS*(obj: Pointer): PGLContextClass
|
|
||||||
proc gl_context_get_type*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_context_get_type".}
|
|
||||||
proc context_new*(gldrawable: PGLDrawable, share_list: PGLContext,
|
|
||||||
direct: gboolean, render_type: int32): PGLContext{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gdk_gl_context_new".}
|
|
||||||
proc destroy*(glcontext: PGLContext){.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_context_destroy".}
|
|
||||||
proc copy*(glcontext: PGLContext, src: PGLContext, mask: int32): gboolean{.
|
|
||||||
cdecl, dynlib: GLExtLib, importc: "gdk_gl_context_copy".}
|
|
||||||
proc get_gl_drawable*(glcontext: PGLContext): PGLDrawable{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gdk_gl_context_get_gl_drawable".}
|
|
||||||
proc get_gl_config*(glcontext: PGLContext): PGLConfig{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gdk_gl_context_get_gl_config".}
|
|
||||||
proc get_share_list*(glcontext: PGLContext): PGLContext{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gdk_gl_context_get_share_list".}
|
|
||||||
proc is_direct*(glcontext: PGLContext): gboolean{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gdk_gl_context_is_direct".}
|
|
||||||
proc get_render_type*(glcontext: PGLContext): int32{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gdk_gl_context_get_render_type".}
|
|
||||||
proc gl_context_get_current*(): PGLContext{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_context_get_current".}
|
|
||||||
proc TYPE_GL_DRAWABLE*(): GType
|
|
||||||
proc GL_DRAWABLE*(inst: Pointer): PGLDrawable
|
|
||||||
proc GL_DRAWABLE_CLASS*(vtable: Pointer): PGLDrawableClass
|
|
||||||
proc IS_GL_DRAWABLE*(inst: Pointer): bool
|
|
||||||
proc IS_GL_DRAWABLE_CLASS*(vtable: Pointer): bool
|
|
||||||
proc GL_DRAWABLE_GET_CLASS*(inst: Pointer): PGLDrawableClass
|
|
||||||
proc gl_drawable_get_type*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_drawable_get_type".}
|
|
||||||
proc make_current*(gldrawable: PGLDrawable, glcontext: PGLContext): gboolean{.
|
|
||||||
cdecl, dynlib: GLExtLib, importc: "gdk_gl_drawable_make_current".}
|
|
||||||
proc is_double_buffered*(gldrawable: PGLDrawable): gboolean{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gdk_gl_drawable_is_double_buffered".}
|
|
||||||
proc swap_buffers*(gldrawable: PGLDrawable){.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gdk_gl_drawable_swap_buffers".}
|
|
||||||
proc wait_gl*(gldrawable: PGLDrawable){.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_drawable_wait_gl".}
|
|
||||||
proc wait_gdk*(gldrawable: PGLDrawable){.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_drawable_wait_gdk".}
|
|
||||||
proc gl_begin*(gldrawable: PGLDrawable, glcontext: PGLContext): gboolean{.
|
|
||||||
cdecl, dynlib: GLExtLib, importc: "gdk_gl_drawable_gl_begin".}
|
|
||||||
proc gl_end*(gldrawable: PGLDrawable){.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_drawable_gl_end".}
|
|
||||||
proc get_gl_config*(gldrawable: PGLDrawable): PGLConfig{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gdk_gl_drawable_get_gl_config".}
|
|
||||||
proc get_size*(gldrawable: PGLDrawable, width, height: PGInt){.
|
|
||||||
cdecl, dynlib: GLExtLib, importc: "gdk_gl_drawable_get_size".}
|
|
||||||
proc gl_drawable_get_current*(): PGLDrawable{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_drawable_get_current".}
|
|
||||||
proc TYPE_GL_PIXMAP*(): GType
|
|
||||||
proc GL_PIXMAP*(anObject: Pointer): PGLPixmap
|
|
||||||
proc GL_PIXMAP_CLASS*(klass: Pointer): PGLPixmapClass
|
|
||||||
proc IS_GL_PIXMAP*(anObject: Pointer): bool
|
|
||||||
proc IS_GL_PIXMAP_CLASS*(klass: Pointer): bool
|
|
||||||
proc GL_PIXMAP_GET_CLASS*(obj: Pointer): PGLPixmapClass
|
|
||||||
proc gl_pixmap_get_type*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_pixmap_get_type".}
|
|
||||||
proc pixmap_new*(glconfig: PGLConfig, pixmap: PPixmap, attrib_list: ptr int32): PGLPixmap{.
|
|
||||||
cdecl, dynlib: GLExtLib, importc: "gdk_gl_pixmap_new".}
|
|
||||||
proc destroy*(glpixmap: PGLPixmap){.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_pixmap_destroy".}
|
|
||||||
proc get_pixmap*(glpixmap: PGLPixmap): PPixmap{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gdk_gl_pixmap_get_pixmap".}
|
|
||||||
proc set_gl_capability*(pixmap: PPixmap, glconfig: PGLConfig,
|
|
||||||
attrib_list: ptr int32): PGLPixmap{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gdk_pixmap_set_gl_capability".}
|
|
||||||
proc unset_gl_capability*(pixmap: PPixmap){.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_pixmap_unset_gl_capability".}
|
|
||||||
proc is_gl_capable*(pixmap: PPixmap): gboolean{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_pixmap_is_gl_capable".}
|
|
||||||
proc get_gl_pixmap*(pixmap: PPixmap): PGLPixmap{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_pixmap_get_gl_pixmap".}
|
|
||||||
proc get_gl_drawable*(pixmap: PPixmap): PGLDrawable
|
|
||||||
proc TYPE_GL_WINDOW*(): GType
|
|
||||||
proc GL_WINDOW*(anObject: Pointer): PGLWindow
|
|
||||||
proc GL_WINDOW_CLASS*(klass: Pointer): PGLWindowClass
|
|
||||||
proc IS_GL_WINDOW*(anObject: Pointer): bool
|
|
||||||
proc IS_GL_WINDOW_CLASS*(klass: Pointer): bool
|
|
||||||
proc GL_WINDOW_GET_CLASS*(obj: Pointer): PGLWindowClass
|
|
||||||
proc gl_window_get_type*(): GType{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_window_get_type".}
|
|
||||||
proc window_new*(glconfig: PGLConfig, window: PWindow, attrib_list: ptr int32): PGLWindow{.
|
|
||||||
cdecl, dynlib: GLExtLib, importc: "gdk_gl_window_new".}
|
|
||||||
proc destroy*(glwindow: PGLWindow){.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_window_destroy".}
|
|
||||||
proc get_window*(glwindow: PGLWindow): PWindow{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gdk_gl_window_get_window".}
|
|
||||||
proc set_gl_capability*(window: PWindow, glconfig: PGLConfig,
|
|
||||||
attrib_list: ptr int32): PGLWindow{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gdk_window_set_gl_capability".}
|
|
||||||
proc unset_gl_capability*(window: PWindow){.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_window_unset_gl_capability".}
|
|
||||||
proc is_gl_capable*(window: PWindow): gboolean{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_window_is_gl_capable".}
|
|
||||||
proc get_gl_window*(window: PWindow): PGLWindow{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_window_get_gl_window".}
|
|
||||||
proc get_gl_drawable*(window: PWindow): PGLDrawable
|
|
||||||
proc gl_draw_cube*(solid: gboolean, size: float64){.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_draw_cube".}
|
|
||||||
proc gl_draw_sphere*(solid: gboolean, radius: float64, slices: int32,
|
|
||||||
stacks: int32){.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_draw_sphere".}
|
|
||||||
proc gl_draw_cone*(solid: gboolean, base: float64, height: float64,
|
|
||||||
slices: int32, stacks: int32){.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_draw_cone".}
|
|
||||||
proc gl_draw_torus*(solid: gboolean, inner_radius: float64,
|
|
||||||
outer_radius: float64, nsides: int32, rings: int32){.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gdk_gl_draw_torus".}
|
|
||||||
proc gl_draw_tetrahedron*(solid: gboolean){.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_draw_tetrahedron".}
|
|
||||||
proc gl_draw_octahedron*(solid: gboolean){.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_draw_octahedron".}
|
|
||||||
proc gl_draw_dodecahedron*(solid: gboolean){.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_draw_dodecahedron".}
|
|
||||||
proc gl_draw_icosahedron*(solid: gboolean){.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_draw_icosahedron".}
|
|
||||||
proc gl_draw_teapot*(solid: gboolean, scale: float64){.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gdk_gl_draw_teapot".}
|
|
||||||
proc HEADER_GDKGLEXT_CHECK_VERSION*(major, minor, micro: guint): bool =
|
|
||||||
result = (HEADER_GDKGLEXT_MAJOR_VERSION > major) or
|
|
||||||
((HEADER_GDKGLEXT_MAJOR_VERSION == major) and
|
|
||||||
(HEADER_GDKGLEXT_MINOR_VERSION > minor)) or
|
|
||||||
((HEADER_GDKGLEXT_MAJOR_VERSION == major) and
|
|
||||||
(HEADER_GDKGLEXT_MINOR_VERSION == minor) and
|
|
||||||
(HEADER_GDKGLEXT_MICRO_VERSION >= micro))
|
|
||||||
|
|
||||||
proc TYPE_GL_CONFIG*(): GType =
|
|
||||||
result = gl_config_get_type()
|
|
||||||
|
|
||||||
proc GL_CONFIG*(anObject: Pointer): PGLConfig =
|
|
||||||
result = cast[PGLConfig](G_TYPE_CHECK_INSTANCE_CAST(anObject, TYPE_GL_CONFIG()))
|
|
||||||
|
|
||||||
proc GL_CONFIG_CLASS*(klass: Pointer): PGLConfigClass =
|
|
||||||
result = cast[PGLConfigClass](G_TYPE_CHECK_CLASS_CAST(klass, TYPE_GL_CONFIG()))
|
|
||||||
|
|
||||||
proc IS_GL_CONFIG*(anObject: Pointer): bool =
|
|
||||||
result = G_TYPE_CHECK_INSTANCE_TYPE(anObject, TYPE_GL_CONFIG())
|
|
||||||
|
|
||||||
proc IS_GL_CONFIG_CLASS*(klass: Pointer): bool =
|
|
||||||
result = G_TYPE_CHECK_CLASS_TYPE(klass, TYPE_GL_CONFIG())
|
|
||||||
|
|
||||||
proc GL_CONFIG_GET_CLASS*(obj: Pointer): PGLConfigClass =
|
|
||||||
result = cast[PGLConfigClass](G_TYPE_INSTANCE_GET_CLASS(obj, TYPE_GL_CONFIG()))
|
|
||||||
|
|
||||||
proc TYPE_GL_CONTEXT*(): GType =
|
|
||||||
result = gl_context_get_type()
|
|
||||||
|
|
||||||
proc GL_CONTEXT*(anObject: Pointer): PGLContext =
|
|
||||||
result = cast[PGLContext](G_TYPE_CHECK_INSTANCE_CAST(anObject,
|
|
||||||
TYPE_GL_CONTEXT()))
|
|
||||||
|
|
||||||
proc GL_CONTEXT_CLASS*(klass: Pointer): PGLContextClass =
|
|
||||||
result = cast[PGLContextClass](G_TYPE_CHECK_CLASS_CAST(klass,
|
|
||||||
TYPE_GL_CONTEXT()))
|
|
||||||
|
|
||||||
proc IS_GL_CONTEXT*(anObject: Pointer): bool =
|
|
||||||
result = G_TYPE_CHECK_INSTANCE_TYPE(anObject, TYPE_GL_CONTEXT())
|
|
||||||
|
|
||||||
proc IS_GL_CONTEXT_CLASS*(klass: Pointer): bool =
|
|
||||||
result = G_TYPE_CHECK_CLASS_TYPE(klass, TYPE_GL_CONTEXT())
|
|
||||||
|
|
||||||
proc GL_CONTEXT_GET_CLASS*(obj: Pointer): PGLContextClass =
|
|
||||||
result = cast[PGLContextClass](G_TYPE_INSTANCE_GET_CLASS(obj,
|
|
||||||
TYPE_GL_CONTEXT()))
|
|
||||||
|
|
||||||
proc TYPE_GL_DRAWABLE*(): GType =
|
|
||||||
result = gl_drawable_get_type()
|
|
||||||
|
|
||||||
proc GL_DRAWABLE*(inst: Pointer): PGLDrawable =
|
|
||||||
result = cast[PGLDrawable](G_TYPE_CHECK_INSTANCE_CAST(inst, TYPE_GL_DRAWABLE()))
|
|
||||||
|
|
||||||
proc GL_DRAWABLE_CLASS*(vtable: Pointer): PGLDrawableClass =
|
|
||||||
result = cast[PGLDrawableClass](G_TYPE_CHECK_CLASS_CAST(vtable,
|
|
||||||
TYPE_GL_DRAWABLE()))
|
|
||||||
|
|
||||||
proc IS_GL_DRAWABLE*(inst: Pointer): bool =
|
|
||||||
result = G_TYPE_CHECK_INSTANCE_TYPE(inst, TYPE_GL_DRAWABLE())
|
|
||||||
|
|
||||||
proc IS_GL_DRAWABLE_CLASS*(vtable: Pointer): bool =
|
|
||||||
result = G_TYPE_CHECK_CLASS_TYPE(vtable, TYPE_GL_DRAWABLE())
|
|
||||||
|
|
||||||
proc GL_DRAWABLE_GET_CLASS*(inst: Pointer): PGLDrawableClass =
|
|
||||||
result = cast[PGLDrawableClass](G_TYPE_INSTANCE_GET_INTERFACE(inst,
|
|
||||||
TYPE_GL_DRAWABLE()))
|
|
||||||
|
|
||||||
proc TYPE_GL_PIXMAP*(): GType =
|
|
||||||
result = gl_pixmap_get_type()
|
|
||||||
|
|
||||||
proc GL_PIXMAP*(anObject: Pointer): PGLPixmap =
|
|
||||||
result = cast[PGLPixmap](G_TYPE_CHECK_INSTANCE_CAST(anObject, TYPE_GL_PIXMAP()))
|
|
||||||
|
|
||||||
proc GL_PIXMAP_CLASS*(klass: Pointer): PGLPixmapClass =
|
|
||||||
result = cast[PGLPixmapClass](G_TYPE_CHECK_CLASS_CAST(klass, TYPE_GL_PIXMAP()))
|
|
||||||
|
|
||||||
proc IS_GL_PIXMAP*(anObject: Pointer): bool =
|
|
||||||
result = G_TYPE_CHECK_INSTANCE_TYPE(anObject, TYPE_GL_PIXMAP())
|
|
||||||
|
|
||||||
proc IS_GL_PIXMAP_CLASS*(klass: Pointer): bool =
|
|
||||||
result = G_TYPE_CHECK_CLASS_TYPE(klass, TYPE_GL_PIXMAP())
|
|
||||||
|
|
||||||
proc GL_PIXMAP_GET_CLASS*(obj: Pointer): PGLPixmapClass =
|
|
||||||
result = cast[PGLPixmapClass](G_TYPE_INSTANCE_GET_CLASS(obj, TYPE_GL_PIXMAP()))
|
|
||||||
|
|
||||||
proc get_gl_drawable*(pixmap: PPixmap): PGLDrawable =
|
|
||||||
result = GL_DRAWABLE(get_gl_pixmap(pixmap))
|
|
||||||
|
|
||||||
proc TYPE_GL_WINDOW*(): GType =
|
|
||||||
result = gl_window_get_type()
|
|
||||||
|
|
||||||
proc GL_WINDOW*(anObject: Pointer): PGLWindow =
|
|
||||||
result = cast[PGLWindow](G_TYPE_CHECK_INSTANCE_CAST(anObject, TYPE_GL_WINDOW()))
|
|
||||||
|
|
||||||
proc GL_WINDOW_CLASS*(klass: Pointer): PGLWindowClass =
|
|
||||||
result = cast[PGLWindowClass](G_TYPE_CHECK_CLASS_CAST(klass, TYPE_GL_WINDOW()))
|
|
||||||
|
|
||||||
proc IS_GL_WINDOW*(anObject: Pointer): bool =
|
|
||||||
result = G_TYPE_CHECK_INSTANCE_TYPE(anObject, TYPE_GL_WINDOW())
|
|
||||||
|
|
||||||
proc IS_GL_WINDOW_CLASS*(klass: Pointer): bool =
|
|
||||||
result = G_TYPE_CHECK_CLASS_TYPE(klass, TYPE_GL_WINDOW())
|
|
||||||
|
|
||||||
proc GL_WINDOW_GET_CLASS*(obj: Pointer): PGLWindowClass =
|
|
||||||
result = cast[PGLWindowClass](G_TYPE_INSTANCE_GET_CLASS(obj, TYPE_GL_WINDOW()))
|
|
||||||
|
|
||||||
proc get_gl_drawable*(window: PWindow): PGLDrawable =
|
|
||||||
result = GL_DRAWABLE(get_gl_window(window))
|
|
||||||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -1,53 +0,0 @@
|
||||||
{.deadCodeElim: on.}
|
|
||||||
import
|
|
||||||
Glib2, Gdk2, gtk2, GdkGLExt
|
|
||||||
|
|
||||||
when defined(windows):
|
|
||||||
const
|
|
||||||
GLExtLib* = "libgtkglext-win32-1.0-0.dll"
|
|
||||||
elif defined(macosx):
|
|
||||||
const
|
|
||||||
GLExtLib* = "libgtkglext-x11-1.0.dylib"
|
|
||||||
else:
|
|
||||||
const
|
|
||||||
GLExtLib* = "libgtkglext-x11-1.0.so"
|
|
||||||
|
|
||||||
const
|
|
||||||
HEADER_GTKGLEXT_MAJOR_VERSION* = 1
|
|
||||||
HEADER_GTKGLEXT_MINOR_VERSION* = 0
|
|
||||||
HEADER_GTKGLEXT_MICRO_VERSION* = 6
|
|
||||||
HEADER_GTKGLEXT_INTERFACE_AGE* = 4
|
|
||||||
HEADER_GTKGLEXT_BINARY_AGE* = 6
|
|
||||||
|
|
||||||
proc gl_parse_args*(argc: ptr int32, argv: PPPChar): gboolean{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gtk_gl_parse_args".}
|
|
||||||
proc gl_init_check*(argc: ptr int32, argv: PPPChar): gboolean{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gtk_gl_init_check".}
|
|
||||||
proc gl_init*(argc: ptr int32, argv: PPPChar){.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gtk_gl_init".}
|
|
||||||
proc set_gl_capability*(widget: PWidget, glconfig: PGLConfig,
|
|
||||||
share_list: PGLContext, direct: gboolean,
|
|
||||||
render_type: int): gboolean{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gtk_widget_set_gl_capability".}
|
|
||||||
proc is_gl_capable*(widget: PWidget): gboolean{.cdecl, dynlib: GLExtLib,
|
|
||||||
importc: "gtk_widget_is_gl_capable".}
|
|
||||||
proc get_gl_config*(widget: PWidget): PGLConfig{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gtk_widget_get_gl_config".}
|
|
||||||
proc create_gl_context*(widget: PWidget, share_list: PGLContext,
|
|
||||||
direct: gboolean, render_type: int): PGLContext{.
|
|
||||||
cdecl, dynlib: GLExtLib, importc: "gtk_widget_create_gl_context".}
|
|
||||||
proc get_gl_context*(widget: PWidget): PGLContext{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gtk_widget_get_gl_context".}
|
|
||||||
proc get_gl_window*(widget: PWidget): PGLWindow{.cdecl,
|
|
||||||
dynlib: GLExtLib, importc: "gtk_widget_get_gl_window".}
|
|
||||||
|
|
||||||
proc HEADER_GTKGLEXT_CHECK_VERSION*(major, minor, micro: guint): bool =
|
|
||||||
result = (HEADER_GTKGLEXT_MAJOR_VERSION > major) or
|
|
||||||
((HEADER_GTKGLEXT_MAJOR_VERSION == major) and
|
|
||||||
(HEADER_GTKGLEXT_MINOR_VERSION > minor)) or
|
|
||||||
((HEADER_GTKGLEXT_MAJOR_VERSION == major) and
|
|
||||||
(HEADER_GTKGLEXT_MINOR_VERSION == minor) and
|
|
||||||
(HEADER_GTKGLEXT_MICRO_VERSION >= micro))
|
|
||||||
|
|
||||||
proc get_gl_drawable*(widget: PWidget): PGLDrawable =
|
|
||||||
result = GL_DRAWABLE(get_gl_window(widget))
|
|
||||||
|
|
@ -1,523 +0,0 @@
|
||||||
{.deadCodeElim: on.}
|
|
||||||
import
|
|
||||||
gtk2, glib2, atk, pango, gdk2pixbuf, gdk2
|
|
||||||
|
|
||||||
when defined(windows):
|
|
||||||
const
|
|
||||||
htmllib = "libgtkhtml-win32-2.0-0.dll"
|
|
||||||
elif defined(macosx):
|
|
||||||
const
|
|
||||||
htmllib = "libgtkhtml-2.dylib"
|
|
||||||
else:
|
|
||||||
const
|
|
||||||
htmllib = "libgtkhtml-2.so"
|
|
||||||
const
|
|
||||||
DOM_UNSPECIFIED_EVENT_TYPE_ERR* = 0
|
|
||||||
DOM_INDEX_SIZE_ERR* = 1
|
|
||||||
DOM_DOMSTRING_SIZE_ERR* = 2
|
|
||||||
DOM_HIERARCHY_REQUEST_ERR* = 3
|
|
||||||
DOM_WRONG_DOCUMENT_ERR* = 4
|
|
||||||
DOM_INVALID_CHARACTER_ERR* = 5
|
|
||||||
DOM_NO_DATA_ALLOWED_ERR* = 6
|
|
||||||
DOM_NO_MODIFICATION_ALLOWED_ERR* = 7
|
|
||||||
DOM_NOT_FOUND_ERR* = 8
|
|
||||||
DOM_NOT_SUPPORTED_ERR* = 9
|
|
||||||
DOM_INUSE_ATTRIBUTE_ERR* = 10
|
|
||||||
DOM_INVALID_STATE_ERR* = 11
|
|
||||||
DOM_SYNTAX_ERR* = 12
|
|
||||||
DOM_INVALID_MODIFICATION_ERR* = 13
|
|
||||||
DOM_NAMESPACE_ERR* = 14
|
|
||||||
DOM_INVALID_ACCESS_ERR* = 15
|
|
||||||
DOM_NO_EXCEPTION* = 255
|
|
||||||
DOM_ELEMENT_NODE* = 1
|
|
||||||
DOM_ATTRIBUTE_NODE* = 2
|
|
||||||
DOM_TEXT_NODE* = 3
|
|
||||||
DOM_CDATA_SECTION_NODE* = 4
|
|
||||||
DOM_ENTITY_REFERENCE_NODE* = 5
|
|
||||||
DOM_ENTITY_NODE* = 6
|
|
||||||
DOM_PROCESSING_INSTRUCTION_NODE* = 7
|
|
||||||
DOM_COMMENT_NODE* = 8
|
|
||||||
DOM_DOCUMENT_NODE* = 9
|
|
||||||
DOM_DOCUMENT_TYPE_NODE* = 10
|
|
||||||
DOM_DOCUMENT_FRAGMENT_NODE* = 11
|
|
||||||
DOM_NOTATION_NODE* = 12
|
|
||||||
bm_HtmlFontSpecification_weight* = 0x0000000F
|
|
||||||
bp_HtmlFontSpecification_weight* = 0
|
|
||||||
bm_HtmlFontSpecification_style* = 0x00000030
|
|
||||||
bp_HtmlFontSpecification_style* = 4
|
|
||||||
bm_HtmlFontSpecification_variant* = 0x000000C0
|
|
||||||
bp_HtmlFontSpecification_variant* = 6
|
|
||||||
bm_HtmlFontSpecification_stretch* = 0x00000F00
|
|
||||||
bp_HtmlFontSpecification_stretch* = 8
|
|
||||||
bm_HtmlFontSpecification_decoration* = 0x00007000
|
|
||||||
bp_HtmlFontSpecification_decoration* = 12
|
|
||||||
|
|
||||||
type
|
|
||||||
TDomString* = gchar
|
|
||||||
PDomString* = cstring
|
|
||||||
TDomBoolean* = gboolean
|
|
||||||
TDomException* = gushort
|
|
||||||
TDomTimeStamp* = guint64
|
|
||||||
PDomNode* = ptr TDomNode
|
|
||||||
TDomNode* = object of TGObject
|
|
||||||
xmlnode*: pointer
|
|
||||||
style*: pointer
|
|
||||||
|
|
||||||
PDomException* = ptr TDomException
|
|
||||||
|
|
||||||
PDomNodeClass* = ptr TDomNodeClass
|
|
||||||
TDomNodeClass* = object of TGObjectClass
|
|
||||||
`get_nodeName`*: proc (node: PDomNode): PDomString{.cdecl.}
|
|
||||||
`get_nodeValue`*: proc (node: PDomNode, exc: PDomException): PDomString{.
|
|
||||||
cdecl.}
|
|
||||||
`set_nodeValue`*: proc (node: PDomNode, value: PDomString,
|
|
||||||
exc: PDomException): PDomString{.cdecl.}
|
|
||||||
|
|
||||||
PDomDocument* = ptr TDomDocument
|
|
||||||
TDomDocument*{.final, pure.} = object
|
|
||||||
parent*: PDomNode
|
|
||||||
iterators*: PGSList
|
|
||||||
|
|
||||||
PDomDocumentClass* = ptr TDomDocumentClass
|
|
||||||
TDomDocumentClass*{.final, pure.} = object
|
|
||||||
parent_class*: PDomNodeClass
|
|
||||||
|
|
||||||
PHtmlFocusIterator* = ptr THtmlFocusIterator
|
|
||||||
THtmlFocusIterator* = object of TGObject
|
|
||||||
document*: PDomDocument
|
|
||||||
current_node*: PDomNode
|
|
||||||
|
|
||||||
PHtmlFocusIteratorClass* = ptr THtmlFocusIteratorClass
|
|
||||||
THtmlFocusIteratorClass* = object of TGObjectClass
|
|
||||||
THtmlParserType* = enum
|
|
||||||
HTML_PARSER_TYPE_HTML, HTML_PARSER_TYPE_XML
|
|
||||||
PHtmlParser* = ptr THtmlParser
|
|
||||||
THtmlParser* = object of TGObject
|
|
||||||
parser_type*: THtmlParserType
|
|
||||||
document*: PHtmlDocument
|
|
||||||
stream*: PHtmlStream
|
|
||||||
xmlctxt*: pointer
|
|
||||||
res*: int32
|
|
||||||
chars*: array[0..9, char]
|
|
||||||
blocking*: gboolean
|
|
||||||
blocking_node*: PDomNode
|
|
||||||
|
|
||||||
PHtmlParserClass* = ptr THtmlParserClass
|
|
||||||
THtmlParserClass* = object of gtk2.TObjectClass
|
|
||||||
done_parsing*: proc (parser: PHtmlParser){.cdecl.}
|
|
||||||
new_node*: proc (parser: PHtmlParser, node: PDomNode)
|
|
||||||
parsed_document_node*: proc (parser: PHtmlParser, document: PDomDocument)
|
|
||||||
|
|
||||||
PHtmlStream* = ptr THtmlStream
|
|
||||||
THtmlStreamCloseFunc* = proc (stream: PHtmlStream, user_data: gpointer){.cdecl.}
|
|
||||||
THtmlStreamWriteFunc* = proc (stream: PHtmlStream, buffer: cstring,
|
|
||||||
size: guint, user_data: gpointer){.cdecl.}
|
|
||||||
THtmlStreamCancelFunc* = proc (stream: PHtmlStream, user_data: gpointer,
|
|
||||||
cancel_data: gpointer){.cdecl.}
|
|
||||||
THtmlStream* = object of TGObject
|
|
||||||
write_func*: THtmlStreamWriteFunc
|
|
||||||
close_func*: THtmlStreamCloseFunc
|
|
||||||
cancel_func*: THtmlStreamCancelFunc
|
|
||||||
user_data*: gpointer
|
|
||||||
cancel_data*: gpointer
|
|
||||||
written*: gint
|
|
||||||
mime_type*: cstring
|
|
||||||
|
|
||||||
PHtmlStreamClass* = ptr THtmlStreamClass
|
|
||||||
THtmlStreamClass* = object of TGObjectClass
|
|
||||||
THtmlStreamBufferCloseFunc* = proc (str: cstring, len: gint,
|
|
||||||
user_data: gpointer){.cdecl.}
|
|
||||||
PHtmlContext* = ptr THtmlContext
|
|
||||||
THtmlContext* = object of TGObject
|
|
||||||
documents*: PGSList
|
|
||||||
standard_font*: PHtmlFontSpecification
|
|
||||||
fixed_font*: PHtmlFontSpecification
|
|
||||||
debug_painting*: gboolean
|
|
||||||
|
|
||||||
PHtmlFontSpecification* = ptr THtmlFontSpecification
|
|
||||||
THtmlFontSpecification {.final, pure.} = object
|
|
||||||
|
|
||||||
PHtmlContextClass* = ptr THtmlContextClass
|
|
||||||
THtmlContextClass* = object of TGObjectClass
|
|
||||||
THtmlDocumentState* = enum
|
|
||||||
HTML_DOCUMENT_STATE_DONE, HTML_DOCUMENT_STATE_PARSING
|
|
||||||
PHtmlDocument* = ptr THtmlDocument
|
|
||||||
THtmlDocument* = object of TGObject
|
|
||||||
stylesheets*: PGSList
|
|
||||||
current_stream*: PHtmlStream
|
|
||||||
state*: THtmlDocumentState
|
|
||||||
|
|
||||||
PHtmlDocumentClass* = ptr THtmlDocumentClass
|
|
||||||
THtmlDocumentClass* = object of TGObjectClass
|
|
||||||
request_url*: proc (document: PHtmlDocument, url: cstring,
|
|
||||||
stream: PHtmlStream){.cdecl.}
|
|
||||||
link_clicked*: proc (document: PHtmlDocument, url: cstring){.cdecl.}
|
|
||||||
set_base*: proc (document: PHtmlDocument, url: cstring){.cdecl.}
|
|
||||||
title_changed*: proc (document: PHtmlDocument, new_title: cstring){.cdecl.}
|
|
||||||
submit*: proc (document: PHtmlDocument, `method`: cstring, url: cstring,
|
|
||||||
encoding: cstring){.cdecl.}
|
|
||||||
|
|
||||||
PHtmlView* = ptr THtmlView
|
|
||||||
THtmlView* = object of gtk2.TLayout
|
|
||||||
document*: PHtmlDocument
|
|
||||||
node_table*: PGHashTable
|
|
||||||
relayout_idle_id*: guint
|
|
||||||
relayout_timeout_id*: guint
|
|
||||||
mouse_down_x*: gint
|
|
||||||
mouse_down_y*: gint
|
|
||||||
mouse_detail*: gint
|
|
||||||
sel_start_ypos*: gint
|
|
||||||
sel_start_index*: gint
|
|
||||||
sel_end_ypos*: gint
|
|
||||||
sel_end_index*: gint
|
|
||||||
sel_flag*: gboolean
|
|
||||||
sel_backwards*: gboolean
|
|
||||||
sel_start_found*: gboolean
|
|
||||||
sel_list*: PGSList
|
|
||||||
jump_to_anchor*: cstring
|
|
||||||
magnification*: gdouble
|
|
||||||
magnification_modified*: gboolean
|
|
||||||
on_url*: gboolean
|
|
||||||
|
|
||||||
PHtmlViewClass* = ptr THtmlViewClass
|
|
||||||
THtmlViewClass* = object of gtk2.TLayoutClass
|
|
||||||
move_cursor*: proc (html_view: PHtmlView, step: TMovementStep, count: gint,
|
|
||||||
extend_selection: gboolean){.cdecl.}
|
|
||||||
on_url*: proc (html_view: PHtmlView, url: cstring)
|
|
||||||
activate*: proc (html_view: PHtmlView)
|
|
||||||
move_focus_out*: proc (html_view: PHtmlView, direction: TDirectionType)
|
|
||||||
|
|
||||||
PDomNodeList* = ptr TDomNodeList
|
|
||||||
TDomNodeList {.pure, final.} = object
|
|
||||||
|
|
||||||
PDomNamedNodeMap* = ptr TDomNamedNodeMap
|
|
||||||
TDomNamedNodeMap {.pure, final.} = object
|
|
||||||
|
|
||||||
PDomDocumentType* = ptr TDomDocumentType
|
|
||||||
TDomDocumentType {.pure, final.} = object
|
|
||||||
|
|
||||||
PDomElement* = ptr TDomElement
|
|
||||||
TDomElement = object of TDomNode
|
|
||||||
|
|
||||||
PDomText* = ptr TDomText
|
|
||||||
TDomText = object of TDomNode
|
|
||||||
|
|
||||||
PDomComment* = ptr TDomComment
|
|
||||||
TDomComment = object of TDomNode
|
|
||||||
|
|
||||||
THtmlBox {.pure, final.} = object
|
|
||||||
PHtmlBox* = ptr THtmlBox
|
|
||||||
|
|
||||||
|
|
||||||
proc DOM_TYPE_NODE*(): GType
|
|
||||||
proc DOM_NODE*(theobject: pointer): PDomNode
|
|
||||||
proc DOM_NODE_CLASS*(klass: pointer): PDomNodeClass
|
|
||||||
proc DOM_IS_NODE*(theobject: pointer): bool
|
|
||||||
proc DOM_IS_NODE_CLASS*(klass: pointer): bool
|
|
||||||
proc DOM_NODE_GET_CLASS*(obj: pointer): int32
|
|
||||||
proc dom_node_get_type*(): GType{.cdecl, dynlib: htmllib,
|
|
||||||
importc: "dom_node_get_type".}
|
|
||||||
proc dom_Node_mkref*(node: pointer): PDomNode{.cdecl, dynlib: htmllib,
|
|
||||||
importc: "dom_Node_mkref".}
|
|
||||||
proc get_childNodes*(node: PDomNode): PDomNodeList{.cdecl,
|
|
||||||
dynlib: htmllib, importc: "dom_Node__get_childNodes".}
|
|
||||||
proc removeChild*(node: PDomNode, oldChild: PDomNode,
|
|
||||||
exc: PDomException): PDomNode{.cdecl,
|
|
||||||
dynlib: htmllib, importc: "dom_Node_removeChild".}
|
|
||||||
proc get_nodeValue*(node: PDomNode, exc: PDomException): PDomString{.
|
|
||||||
cdecl, dynlib: htmllib, importc: "dom_Node__get_nodeValue".}
|
|
||||||
proc get_firstChild*(node: PDomNode): PDomNode{.cdecl,
|
|
||||||
dynlib: htmllib, importc: "dom_Node__get_firstChild".}
|
|
||||||
proc get_nodeName*(node: PDomNode): PDomString{.cdecl,
|
|
||||||
dynlib: htmllib, importc: "dom_Node__get_nodeName".}
|
|
||||||
proc get_attributes*(node: PDomNode): PDomNamedNodeMap{.cdecl,
|
|
||||||
dynlib: htmllib, importc: "dom_Node__get_attributes".}
|
|
||||||
proc get_doctype*(doc: PDomDocument): PDomDocumentType{.cdecl,
|
|
||||||
dynlib: htmllib, importc: "dom_Document__get_doctype".}
|
|
||||||
proc hasChildNodes*(node: PDomNode): bool{.cdecl,
|
|
||||||
dynlib: htmllib, importc: "dom_Node_hasChildNodes".}
|
|
||||||
proc get_parentNode*(node: PDomNode): PDomNode{.cdecl,
|
|
||||||
dynlib: htmllib, importc: "dom_Node__get_parentNode".}
|
|
||||||
proc get_nextSibling*(node: PDomNode): PDomNode{.cdecl,
|
|
||||||
dynlib: htmllib, importc: "dom_Node__get_nextSibling".}
|
|
||||||
proc get_nodeType*(node: PDomNode): gushort{.cdecl, dynlib: htmllib,
|
|
||||||
importc: "dom_Node__get_nodeType".}
|
|
||||||
|
|
||||||
proc cloneNode*(node: PDomNode, deep: bool): PDomNode{.cdecl,
|
|
||||||
dynlib: htmllib, importc: "dom_Node_cloneNode".}
|
|
||||||
proc appendChild*(node: PDomNode, newChild: PDomNode,
|
|
||||||
exc: PDomException): PDomNode{.cdecl,
|
|
||||||
dynlib: htmllib, importc: "dom_Node_appendChild".}
|
|
||||||
proc get_localName*(node: PDomNode): PDomString{.cdecl,
|
|
||||||
dynlib: htmllib, importc: "dom_Node__get_localName".}
|
|
||||||
proc get_namespaceURI*(node: PDomNode): PDomString{.cdecl,
|
|
||||||
dynlib: htmllib, importc: "dom_Node__get_namespaceURI".}
|
|
||||||
proc get_previousSibling*(node: PDomNode): PDomNode{.cdecl,
|
|
||||||
dynlib: htmllib, importc: "dom_Node__get_previousSibling".}
|
|
||||||
proc get_lastChild*(node: PDomNode): PDomNode{.cdecl, dynlib: htmllib,
|
|
||||||
importc: "dom_Node__get_lastChild".}
|
|
||||||
proc set_nodeValue*(node: PDomNode, value: PDomString,
|
|
||||||
exc: PDomException){.cdecl, dynlib: htmllib,
|
|
||||||
importc: "dom_Node__set_nodeValue".}
|
|
||||||
proc get_ownerDocument*(node: PDomNode): PDomDocument{.cdecl,
|
|
||||||
dynlib: htmllib, importc: "dom_Node__get_ownerDocument".}
|
|
||||||
proc hasAttributes*(node: PDomNode): gboolean{.cdecl, dynlib: htmllib,
|
|
||||||
importc: "dom_Node_hasAttributes".}
|
|
||||||
proc DOM_TYPE_DOCUMENT*(): GType
|
|
||||||
proc DOM_DOCUMENT*(theobject: pointer): PDomDocument
|
|
||||||
proc DOM_DOCUMENT_CLASS*(klass: pointer): PDomDocumentClass
|
|
||||||
proc DOM_IS_DOCUMENT*(theobject: pointer): bool
|
|
||||||
proc DOM_IS_DOCUMENT_CLASS*(klass: pointer): bool
|
|
||||||
proc DOM_DOCUMENT_GET_CLASS*(obj: pointer): PDomDocumentClass
|
|
||||||
proc dom_document_get_type*(): GType
|
|
||||||
proc get_documentElement*(doc: PDomDocument): PDomElement
|
|
||||||
proc createElement*(doc: PDomDocument, tagName: PDomString): PDomElement
|
|
||||||
proc createTextNode*(doc: PDomDocument, data: PDomString): PDomText
|
|
||||||
proc createComment*(doc: PDomDocument, data: PDomString): PDomComment
|
|
||||||
proc importNode*(doc: PDomDocument, importedNode: PDomNode,
|
|
||||||
deep: bool, exc: PDomException): PDomNode
|
|
||||||
proc HTML_TYPE_FOCUS_ITERATOR*(): GType
|
|
||||||
proc HTML_FOCUS_ITERATOR*(theobject: pointer): PHtmlFocusIterator
|
|
||||||
proc HTML_FOCUS_ITERATOR_CLASS*(klass: pointer): PHtmlFocusIteratorClass
|
|
||||||
proc HTML_IS_FOCUS_ITERATOR*(theobject: pointer): bool
|
|
||||||
proc HTML_IS_FOCUS_ITERATOR_CLASS*(klass: pointer): bool
|
|
||||||
proc HTML_FOCUS_ITERATOR_GET_CLASS*(obj: pointer): PHtmlFocusIteratorClass
|
|
||||||
proc html_focus_iterator_next_element*(document: PDomDocument,
|
|
||||||
element: PDomElement): PDomElement{.
|
|
||||||
cdecl, dynlib: htmllib, importc: "html_focus_iterator_next_element".}
|
|
||||||
proc html_focus_iterator_prev_element*(document: PDomDocument,
|
|
||||||
element: PDomElement): PDomElement{.
|
|
||||||
cdecl, dynlib: htmllib, importc: "html_focus_iterator_prev_element".}
|
|
||||||
proc HTML_PARSER_TYPE*(): GType
|
|
||||||
proc HTML_PARSER*(obj: pointer): PHtmlParser
|
|
||||||
proc HTML_PARSER_CLASS*(klass: pointer): PHtmlParserClass
|
|
||||||
proc HTML_IS_PARSER*(obj: pointer): bool
|
|
||||||
proc html_parser_get_type*(): GType
|
|
||||||
proc parser_new*(document: PHtmlDocument, parser_type: THtmlParserType): PHtmlParser
|
|
||||||
proc HTML_TYPE_STREAM*(): GType
|
|
||||||
proc HTML_STREAM*(obj: pointer): PHtmlStream
|
|
||||||
proc HTML_STREAM_CLASS*(klass: pointer): PHtmlStreamClass
|
|
||||||
proc HTML_IS_STREAM*(obj: pointer): bool
|
|
||||||
proc HTML_IS_STREAM_CLASS*(klass: pointer): bool
|
|
||||||
proc HTML_STREAM_GET_CLASS*(obj: pointer): PHtmlStreamClass
|
|
||||||
proc html_stream_get_type*(): GType{.cdecl, dynlib: htmllib,
|
|
||||||
importc: "html_stream_get_type".}
|
|
||||||
proc html_stream_new*(write_func: THtmlStreamWriteFunc,
|
|
||||||
close_func: THtmlStreamCloseFunc, user_data: gpointer): PHtmlStream{.
|
|
||||||
cdecl, dynlib: htmllib, importc: "html_stream_new".}
|
|
||||||
proc write*(stream: PHtmlStream, buffer: cstring, size: guint){.
|
|
||||||
cdecl, dynlib: htmllib, importc: "html_stream_write".}
|
|
||||||
proc close*(stream: PHtmlStream){.cdecl, dynlib: htmllib,
|
|
||||||
importc: "html_stream_close".}
|
|
||||||
proc destroy*(stream: PHtmlStream){.cdecl, dynlib: htmllib,
|
|
||||||
importc: "html_stream_destroy".}
|
|
||||||
proc get_written*(stream: PHtmlStream): gint{.cdecl,
|
|
||||||
dynlib: htmllib, importc: "html_stream_get_written".}
|
|
||||||
proc cancel*(stream: PHtmlStream){.cdecl, dynlib: htmllib,
|
|
||||||
importc: "html_stream_cancel".}
|
|
||||||
proc set_cancel_func*(stream: PHtmlStream,
|
|
||||||
abort_func: THtmlStreamCancelFunc,
|
|
||||||
cancel_data: gpointer){.cdecl,
|
|
||||||
dynlib: htmllib, importc: "html_stream_set_cancel_func".}
|
|
||||||
proc get_mime_type*(stream: PHtmlStream): cstring{.cdecl,
|
|
||||||
dynlib: htmllib, importc: "html_stream_get_mime_type".}
|
|
||||||
proc set_mime_type*(stream: PHtmlStream, mime_type: cstring){.cdecl,
|
|
||||||
dynlib: htmllib, importc: "html_stream_set_mime_type".}
|
|
||||||
proc html_stream_buffer_new*(close_func: THtmlStreamBufferCloseFunc,
|
|
||||||
user_data: gpointer): PHtmlStream{.cdecl,
|
|
||||||
dynlib: htmllib, importc: "html_stream_buffer_new".}
|
|
||||||
proc event_mouse_move*(view: PHtmlView, event: Gdk2.PEventMotion){.cdecl,
|
|
||||||
dynlib: htmllib, importc: "html_event_mouse_move".}
|
|
||||||
proc event_button_press*(view: PHtmlView, button: Gdk2.PEventButton){.cdecl,
|
|
||||||
dynlib: htmllib, importc: "html_event_button_press".}
|
|
||||||
proc event_button_release*(view: PHtmlView, event: Gdk2.PEventButton){.cdecl,
|
|
||||||
dynlib: htmllib, importc: "html_event_button_release".}
|
|
||||||
proc event_activate*(view: PHtmlView){.cdecl, dynlib: htmllib,
|
|
||||||
importc: "html_event_activate".}
|
|
||||||
proc event_key_press*(view: PHtmlView, event: Gdk2.PEventKey): gboolean{.
|
|
||||||
cdecl, dynlib: htmllib, importc: "html_event_key_press".}
|
|
||||||
proc event_find_root_box*(self: PHtmlBox, x: gint, y: gint): PHtmlBox{.
|
|
||||||
cdecl, dynlib: htmllib, importc: "html_event_find_root_box".}
|
|
||||||
proc selection_start*(view: PHtmlView, event: Gdk2.PEventButton){.cdecl,
|
|
||||||
dynlib: htmllib, importc: "html_selection_start".}
|
|
||||||
proc selection_end*(view: PHtmlView, event: Gdk2.PEventButton){.cdecl,
|
|
||||||
dynlib: htmllib, importc: "html_selection_end".}
|
|
||||||
proc selection_update*(view: PHtmlView, event: Gdk2.PEventMotion){.cdecl,
|
|
||||||
dynlib: htmllib, importc: "html_selection_update".}
|
|
||||||
proc selection_clear*(view: PHtmlView){.cdecl, dynlib: htmllib,
|
|
||||||
importc: "html_selection_clear".}
|
|
||||||
proc selection_set*(view: PHtmlView, start: PDomNode, offset: int32,
|
|
||||||
len: int32){.cdecl, dynlib: htmllib,
|
|
||||||
importc: "html_selection_set".}
|
|
||||||
proc HTML_CONTEXT_TYPE*(): GType
|
|
||||||
proc HTML_CONTEXT*(obj: pointer): PHtmlContext
|
|
||||||
proc HTML_CONTEXT_CLASS*(klass: pointer): PHtmlContextClass
|
|
||||||
proc HTML_IS_CONTEXT*(obj: pointer): bool
|
|
||||||
proc HTML_IS_CONTEXT_CLASS*(klass: pointer): bool
|
|
||||||
proc html_context_get_type*(): GType
|
|
||||||
proc html_context_get*(): PHtmlContext
|
|
||||||
proc HTML_TYPE_DOCUMENT*(): GType
|
|
||||||
proc HTML_DOCUMENT*(obj: pointer): PHtmlDocument
|
|
||||||
proc HTML_DOCUMENT_CLASS*(klass: pointer): PHtmlDocumentClass
|
|
||||||
proc HTML_IS_DOCUMENT*(obj: pointer): bool
|
|
||||||
proc html_document_get_type*(): GType{.cdecl, dynlib: htmllib,
|
|
||||||
importc: "html_document_get_type".}
|
|
||||||
proc html_document_new*(): PHtmlDocument{.cdecl, dynlib: htmllib,
|
|
||||||
importc: "html_document_new".}
|
|
||||||
proc open_stream*(document: PHtmlDocument, mime_type: cstring): gboolean{.
|
|
||||||
cdecl, dynlib: htmllib, importc: "html_document_open_stream".}
|
|
||||||
proc write_stream*(document: PHtmlDocument, buffer: cstring,
|
|
||||||
len: gint){.cdecl, dynlib: htmllib,
|
|
||||||
importc: "html_document_write_stream".}
|
|
||||||
proc close_stream*(document: PHtmlDocument){.cdecl,
|
|
||||||
dynlib: htmllib, importc: "html_document_close_stream".}
|
|
||||||
proc clear*(document: PHtmlDocument){.cdecl, dynlib: htmllib,
|
|
||||||
importc: "html_document_clear".}
|
|
||||||
proc HTML_TYPE_VIEW*(): GType
|
|
||||||
proc HTML_VIEW*(obj: pointer): PHtmlView
|
|
||||||
proc HTML_VIEW_CLASS*(klass: pointer): PHtmlViewClass
|
|
||||||
proc HTML_IS_VIEW*(obj: pointer): bool
|
|
||||||
proc html_view_get_type*(): GType{.cdecl, dynlib: htmllib,
|
|
||||||
importc: "html_view_get_type".}
|
|
||||||
proc html_view_new*(): PWidget{.cdecl, dynlib: htmllib, importc: "html_view_new".}
|
|
||||||
proc set_document*(view: PHtmlView, document: PHtmlDocument){.cdecl,
|
|
||||||
dynlib: htmllib, importc: "html_view_set_document".}
|
|
||||||
proc jump_to_anchor*(view: PHtmlView, anchor: cstring){.cdecl,
|
|
||||||
dynlib: htmllib, importc: "html_view_jump_to_anchor".}
|
|
||||||
proc get_magnification*(view: PHtmlView): gdouble{.cdecl,
|
|
||||||
dynlib: htmllib, importc: "html_view_get_magnification".}
|
|
||||||
proc set_magnification*(view: PHtmlView, magnification: gdouble){.
|
|
||||||
cdecl, dynlib: htmllib, importc: "html_view_set_magnification".}
|
|
||||||
proc zoom_in*(view: PHtmlView){.cdecl, dynlib: htmllib,
|
|
||||||
importc: "html_view_zoom_in".}
|
|
||||||
proc zoom_out*(view: PHtmlView){.cdecl, dynlib: htmllib,
|
|
||||||
importc: "html_view_zoom_out".}
|
|
||||||
proc zoom_reset*(view: PHtmlView){.cdecl, dynlib: htmllib,
|
|
||||||
importc: "html_view_zoom_reset".}
|
|
||||||
|
|
||||||
proc DOM_TYPE_NODE*(): GType =
|
|
||||||
result = dom_node_get_type()
|
|
||||||
|
|
||||||
proc DOM_NODE*(theobject: pointer): PDomNode =
|
|
||||||
result = G_TYPE_CHECK_INSTANCE_CAST(theobject, DOM_TYPE_NODE())
|
|
||||||
|
|
||||||
proc DOM_NODE_CLASS*(klass: pointer): PDomNodeClass =
|
|
||||||
result = G_TYPE_CHECK_CLASS_CAST(klass, DOM_TYPE_NODE(), TDomNodeClass)
|
|
||||||
|
|
||||||
proc DOM_IS_NODE*(theobject: pointer): bool =
|
|
||||||
result = G_TYPE_CHECK_INSTANCE_TYPE(theobject, DOM_TYPE_NODE())
|
|
||||||
|
|
||||||
proc DOM_IS_NODE_CLASS*(klass: pointer): bool =
|
|
||||||
result = G_TYPE_CHECK_CLASS_TYPE(klass, DOM_TYPE_NODE())
|
|
||||||
|
|
||||||
proc DOM_NODE_GET_CLASS*(obj: pointer): PDomNodeClass =
|
|
||||||
result = G_TYPE_INSTANCE_GET_CLASS(obj, DOM_TYPE_NODE(), TDomNodeClass)
|
|
||||||
|
|
||||||
proc DOM_TYPE_DOCUMENT*(): GType =
|
|
||||||
result = dom_document_get_type()
|
|
||||||
|
|
||||||
proc DOM_DOCUMENT*(theobject: pointer): PDomDocument =
|
|
||||||
result = G_TYPE_CHECK_INSTANCE_CAST(theobject, DOM_TYPE_DOCUMENT(),
|
|
||||||
TDomDocument)
|
|
||||||
|
|
||||||
proc DOM_DOCUMENT_CLASS*(klass: pointer): PDomDocumentClass =
|
|
||||||
result = G_TYPE_CHECK_CLASS_CAST(klass, DOM_TYPE_DOCUMENT(), TDomDocumentClass)
|
|
||||||
|
|
||||||
proc DOM_IS_DOCUMENT*(theobject: pointer): bool =
|
|
||||||
result = G_TYPE_CHECK_INSTANCE_TYPE(theobject, DOM_TYPE_DOCUMENT())
|
|
||||||
|
|
||||||
proc DOM_IS_DOCUMENT_CLASS*(klass: pointer): bool =
|
|
||||||
result = G_TYPE_CHECK_CLASS_TYPE(klass, DOM_TYPE_DOCUMENT())
|
|
||||||
|
|
||||||
proc DOM_DOCUMENT_GET_CLASS*(obj: pointer): PDomDocumentClass =
|
|
||||||
result = G_TYPE_INSTANCE_GET_CLASS(obj, DOM_TYPE_DOCUMENT(), TDomDocumentClass)
|
|
||||||
|
|
||||||
proc HTML_TYPE_FOCUS_ITERATOR*(): GType =
|
|
||||||
result = html_focus_iterator_get_type()
|
|
||||||
|
|
||||||
proc HTML_FOCUS_ITERATOR*(theobject: pointer): PHtmlFocusIterator =
|
|
||||||
result = G_TYPE_CHECK_INSTANCE_CAST(theobject, HTML_TYPE_FOCUS_ITERATOR(),
|
|
||||||
HtmlFocusIterator)
|
|
||||||
|
|
||||||
proc HTML_FOCUS_ITERATOR_CLASS*(klass: pointer): PHtmlFocusIteratorClass =
|
|
||||||
result = G_TYPE_CHECK_CLASS_CAST(klass, HTML_TYPE_FOCUS_ITERATOR(),
|
|
||||||
HtmlFocusIteratorClass)
|
|
||||||
|
|
||||||
proc HTML_IS_FOCUS_ITERATOR*(theobject: pointer): bool =
|
|
||||||
result = G_TYPE_CHECK_INSTANCE_TYPE(theobject, HTML_TYPE_FOCUS_ITERATOR())
|
|
||||||
|
|
||||||
proc HTML_IS_FOCUS_ITERATOR_CLASS*(klass: pointer): bool =
|
|
||||||
result = G_TYPE_CHECK_CLASS_TYPE(klass, HTML_TYPE_FOCUS_ITERATOR())
|
|
||||||
|
|
||||||
proc HTML_FOCUS_ITERATOR_GET_CLASS*(obj: pointer): PHtmlFocusIteratorClass =
|
|
||||||
result = G_TYPE_INSTANCE_GET_CLASS(obj, HTML_TYPE_FOCUS_ITERATOR(),
|
|
||||||
HtmlFocusIteratorClass)
|
|
||||||
|
|
||||||
proc HTML_PARSER_TYPE*(): GType =
|
|
||||||
result = html_parser_get_type()
|
|
||||||
|
|
||||||
proc HTML_PARSER*(obj: pointer): PHtmlParser =
|
|
||||||
result = CHECK_CAST(obj, HTML_PARSER_TYPE(), THtmlParser)
|
|
||||||
|
|
||||||
proc HTML_PARSER_CLASS*(klass: pointer): PHtmlParserClass =
|
|
||||||
result = CHECK_CLASS_CAST(klass, HTML_PARSER_TYPE(), THtmlParserClass)
|
|
||||||
|
|
||||||
proc HTML_IS_PARSER*(obj: pointer): bool =
|
|
||||||
result = CHECK_TYPE(obj, HTML_PARSER_TYPE())
|
|
||||||
|
|
||||||
proc HTML_TYPE_STREAM*(): GType =
|
|
||||||
result = html_stream_get_type()
|
|
||||||
|
|
||||||
proc HTML_STREAM*(obj: pointer): PHtmlStream =
|
|
||||||
result = PHtmlStream(G_TYPE_CHECK_INSTANCE_CAST(obj, HTML_TYPE_STREAM()))
|
|
||||||
|
|
||||||
proc HTML_STREAM_CLASS*(klass: pointer): PHtmlStreamClass =
|
|
||||||
result = G_TYPE_CHECK_CLASS_CAST(klass, HTML_TYPE_STREAM())
|
|
||||||
|
|
||||||
proc HTML_IS_STREAM*(obj: pointer): bool =
|
|
||||||
result = G_TYPE_CHECK_INSTANCE_TYPE(obj, HTML_TYPE_STREAM())
|
|
||||||
|
|
||||||
proc HTML_IS_STREAM_CLASS*(klass: pointer): bool =
|
|
||||||
result = G_TYPE_CHECK_CLASS_TYPE(klass, HTML_TYPE_STREAM())
|
|
||||||
|
|
||||||
proc HTML_STREAM_GET_CLASS*(obj: pointer): PHtmlStreamClass =
|
|
||||||
result = PHtmlStreamClass(G_TYPE_INSTANCE_GET_CLASS(obj, HTML_TYPE_STREAM()))
|
|
||||||
|
|
||||||
proc HTML_CONTEXT_TYPE*(): GType =
|
|
||||||
result = html_context_get_type()
|
|
||||||
|
|
||||||
proc HTML_CONTEXT*(obj: pointer): PHtmlContext =
|
|
||||||
result = CHECK_CAST(obj, HTML_CONTEXT_TYPE(), THtmlContext)
|
|
||||||
|
|
||||||
proc HTML_CONTEXT_CLASS*(klass: pointer): PHtmlContextClass =
|
|
||||||
result = CHECK_CLASS_CAST(klass, HTML_CONTEXT_TYPE(), THtmlContextClass)
|
|
||||||
|
|
||||||
proc HTML_IS_CONTEXT*(obj: pointer): bool =
|
|
||||||
result = CHECK_TYPE(obj, HTML_CONTEXT_TYPE())
|
|
||||||
|
|
||||||
proc HTML_IS_CONTEXT_CLASS*(klass: pointer): bool =
|
|
||||||
result = CHECK_CLASS_TYPE(klass, HTML_CONTEXT_TYPE())
|
|
||||||
|
|
||||||
proc HTML_TYPE_DOCUMENT*(): GType =
|
|
||||||
result = html_document_get_type()
|
|
||||||
|
|
||||||
proc HTML_DOCUMENT*(obj: pointer): PHtmlDocument =
|
|
||||||
result = PHtmlDocument(CHECK_CAST(obj, HTML_TYPE_DOCUMENT()))
|
|
||||||
|
|
||||||
proc HTML_DOCUMENT_CLASS*(klass: pointer): PHtmlDocumentClass =
|
|
||||||
result = CHECK_CLASS_CAST(klass, HTML_TYPE_DOCUMENT())
|
|
||||||
|
|
||||||
proc HTML_IS_DOCUMENT*(obj: pointer): bool =
|
|
||||||
result = CHECK_TYPE(obj, HTML_TYPE_DOCUMENT())
|
|
||||||
|
|
||||||
proc HTML_TYPE_VIEW*(): GType =
|
|
||||||
result = html_view_get_type()
|
|
||||||
|
|
||||||
proc HTML_VIEW*(obj: pointer): PHtmlView =
|
|
||||||
result = PHtmlView(CHECK_CAST(obj, HTML_TYPE_VIEW()))
|
|
||||||
|
|
||||||
proc HTML_VIEW_CLASS*(klass: pointer): PHtmlViewClass =
|
|
||||||
result = PHtmlViewClass(CHECK_CLASS_CAST(klass, HTML_TYPE_VIEW()))
|
|
||||||
|
|
||||||
proc HTML_IS_VIEW*(obj: pointer): bool =
|
|
||||||
result = CHECK_TYPE(obj, HTML_TYPE_VIEW())
|
|
||||||
|
|
@ -1,111 +0,0 @@
|
||||||
{.deadCodeElim: on.}
|
|
||||||
import
|
|
||||||
glib2, gtk2
|
|
||||||
|
|
||||||
when defined(win32):
|
|
||||||
const
|
|
||||||
LibGladeLib = "libglade-2.0-0.dll"
|
|
||||||
elif defined(macosx):
|
|
||||||
const
|
|
||||||
LibGladeLib = "libglade-2.0.dylib"
|
|
||||||
else:
|
|
||||||
const
|
|
||||||
LibGladeLib = "libglade-2.0.so"
|
|
||||||
type
|
|
||||||
PLongint* = ptr int32
|
|
||||||
PSmallInt* = ptr int16
|
|
||||||
PByte* = ptr int8
|
|
||||||
PWord* = ptr int16
|
|
||||||
PDWord* = ptr int32
|
|
||||||
PDouble* = ptr float64
|
|
||||||
|
|
||||||
proc init*(){.cdecl, dynlib: LibGladeLib, importc: "glade_init".}
|
|
||||||
proc require*(TheLibrary: cstring){.cdecl, dynlib: LibGladeLib,
|
|
||||||
importc: "glade_require".}
|
|
||||||
proc provide*(TheLibrary: cstring){.cdecl, dynlib: LibGladeLib,
|
|
||||||
importc: "glade_provide".}
|
|
||||||
type
|
|
||||||
PXMLPrivate* = pointer
|
|
||||||
PXML* = ptr TXML
|
|
||||||
TXML* = object of TGObject
|
|
||||||
filename*: cstring
|
|
||||||
priv*: PXMLPrivate
|
|
||||||
|
|
||||||
PXMLClass* = ptr TXMLClass
|
|
||||||
TXMLClass* = object of TGObjectClass
|
|
||||||
TXMLConnectFunc* = proc (handler_name: cstring, anObject: PGObject,
|
|
||||||
signal_name: cstring, signal_data: cstring,
|
|
||||||
connect_object: PGObject, after: gboolean,
|
|
||||||
user_data: gpointer){.cdecl.}
|
|
||||||
|
|
||||||
proc TYPE_XML*(): GType
|
|
||||||
proc XML*(obj: pointer): PXML
|
|
||||||
proc XML_CLASS*(klass: pointer): PXMLClass
|
|
||||||
proc IS_XML*(obj: pointer): gboolean
|
|
||||||
proc IS_XML_CLASS*(klass: pointer): gboolean
|
|
||||||
proc XML_GET_CLASS*(obj: pointer): PXMLClass
|
|
||||||
proc xml_get_type*(): GType{.cdecl, dynlib: LibGladeLib,
|
|
||||||
importc: "glade_xml_get_type".}
|
|
||||||
proc xml_new*(fname: cstring, root: cstring, domain: cstring): PXML{.cdecl,
|
|
||||||
dynlib: LibGladeLib, importc: "glade_xml_new".}
|
|
||||||
proc xml_new_from_buffer*(buffer: cstring, size: int32, root: cstring,
|
|
||||||
domain: cstring): PXML{.cdecl, dynlib: LibGladeLib,
|
|
||||||
importc: "glade_xml_new_from_buffer".}
|
|
||||||
proc construct*(self: PXML, fname: cstring, root: cstring, domain: cstring): gboolean{.
|
|
||||||
cdecl, dynlib: LibGladeLib, importc: "glade_xml_construct".}
|
|
||||||
proc signal_connect*(self: PXML, handlername: cstring, func: TGCallback){.
|
|
||||||
cdecl, dynlib: LibGladeLib, importc: "glade_xml_signal_connect".}
|
|
||||||
proc signal_connect_data*(self: PXML, handlername: cstring,
|
|
||||||
func: TGCallback, user_data: gpointer){.cdecl,
|
|
||||||
dynlib: LibGladeLib, importc: "glade_xml_signal_connect_data".}
|
|
||||||
proc signal_autoconnect*(self: PXML){.cdecl, dynlib: LibGladeLib,
|
|
||||||
importc: "glade_xml_signal_autoconnect".}
|
|
||||||
proc signal_connect_full*(self: PXML, handler_name: cstring,
|
|
||||||
func: TXMLConnectFunc, user_data: gpointer){.
|
|
||||||
cdecl, dynlib: LibGladeLib, importc: "glade_xml_signal_connect_full".}
|
|
||||||
proc signal_autoconnect_full*(self: PXML, func: TXMLConnectFunc,
|
|
||||||
user_data: gpointer){.cdecl,
|
|
||||||
dynlib: LibGladeLib, importc: "glade_xml_signal_autoconnect_full".}
|
|
||||||
proc get_widget*(self: PXML, name: cstring): gtk2.PWidget{.cdecl,
|
|
||||||
dynlib: LibGladeLib, importc: "glade_xml_get_widget".}
|
|
||||||
proc get_widget_prefix*(self: PXML, name: cstring): PGList{.cdecl,
|
|
||||||
dynlib: LibGladeLib, importc: "glade_xml_get_widget_prefix".}
|
|
||||||
proc relative_file*(self: PXML, filename: cstring): cstring{.cdecl,
|
|
||||||
dynlib: LibGladeLib, importc: "glade_xml_relative_file".}
|
|
||||||
proc get_widget_name*(widget: gtk2.PWidget): cstring{.cdecl, dynlib: LibGladeLib,
|
|
||||||
importc: "glade_get_widget_name".}
|
|
||||||
proc get_widget_tree*(widget: gtk2.PWidget): PXML{.cdecl, dynlib: LibGladeLib,
|
|
||||||
importc: "glade_get_widget_tree".}
|
|
||||||
type
|
|
||||||
PXMLCustomWidgetHandler* = ptr TXMLCustomWidgetHandler
|
|
||||||
TXMLCustomWidgetHandler* = gtk2.TWidget
|
|
||||||
|
|
||||||
proc set_custom_handler*(handler: TXMLCustomWidgetHandler, user_data: gpointer){.
|
|
||||||
cdecl, dynlib: LibGladeLib, importc: "glade_set_custom_handler".}
|
|
||||||
proc gnome_init*() =
|
|
||||||
init()
|
|
||||||
|
|
||||||
proc bonobo_init*() =
|
|
||||||
init()
|
|
||||||
|
|
||||||
proc xml_new_from_memory*(buffer: cstring, size: int32, root: cstring,
|
|
||||||
domain: cstring): PXML =
|
|
||||||
result = xml_new_from_buffer(buffer, size, root, domain)
|
|
||||||
|
|
||||||
proc TYPE_XML*(): GType =
|
|
||||||
result = xml_get_type()
|
|
||||||
|
|
||||||
proc XML*(obj: pointer): PXML =
|
|
||||||
result = cast[PXML](G_TYPE_CHECK_INSTANCE_CAST(obj, TYPE_XML()))
|
|
||||||
|
|
||||||
proc XML_CLASS*(klass: pointer): PXMLClass =
|
|
||||||
result = cast[PXMLClass](G_TYPE_CHECK_CLASS_CAST(klass, TYPE_XML()))
|
|
||||||
|
|
||||||
proc IS_XML*(obj: pointer): gboolean =
|
|
||||||
result = G_TYPE_CHECK_INSTANCE_TYPE(obj, TYPE_XML())
|
|
||||||
|
|
||||||
proc IS_XML_CLASS*(klass: pointer): gboolean =
|
|
||||||
result = G_TYPE_CHECK_CLASS_TYPE(klass, TYPE_XML())
|
|
||||||
|
|
||||||
proc XML_GET_CLASS*(obj: pointer): PXMLClass =
|
|
||||||
result = cast[PXMLClass](G_TYPE_INSTANCE_GET_CLASS(obj, TYPE_XML()))
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,42 +0,0 @@
|
||||||
{.deadCodeElim: on.}
|
|
||||||
import
|
|
||||||
glib2, pango
|
|
||||||
|
|
||||||
proc split_file_list*(str: cstring): PPchar{.cdecl, dynlib: lib,
|
|
||||||
importc: "pango_split_file_list".}
|
|
||||||
proc trim_string*(str: cstring): cstring{.cdecl, dynlib: lib,
|
|
||||||
importc: "pango_trim_string".}
|
|
||||||
proc read_line*(stream: TFile, str: PGString): gint{.cdecl, dynlib: lib,
|
|
||||||
importc: "pango_read_line".}
|
|
||||||
proc skip_space*(pos: PPchar): gboolean{.cdecl, dynlib: lib,
|
|
||||||
importc: "pango_skip_space".}
|
|
||||||
proc scan_word*(pos: PPchar, OutStr: PGString): gboolean{.cdecl, dynlib: lib,
|
|
||||||
importc: "pango_scan_word".}
|
|
||||||
proc scan_string*(pos: PPchar, OutStr: PGString): gboolean{.cdecl, dynlib: lib,
|
|
||||||
importc: "pango_scan_string".}
|
|
||||||
proc scan_int*(pos: PPchar, OutInt: ptr int32): gboolean{.cdecl, dynlib: lib,
|
|
||||||
importc: "pango_scan_int".}
|
|
||||||
proc config_key_get*(key: cstring): cstring{.cdecl, dynlib: lib,
|
|
||||||
importc: "pango_config_key_get".}
|
|
||||||
proc lookup_aliases*(fontname: cstring, families: PPPchar, n_families: ptr int32){.
|
|
||||||
cdecl, dynlib: lib, importc: "pango_lookup_aliases".}
|
|
||||||
proc parse_style*(str: cstring, style: PStyle, warn: gboolean): gboolean{.cdecl,
|
|
||||||
dynlib: lib, importc: "pango_parse_style".}
|
|
||||||
proc parse_variant*(str: cstring, variant: PVariant, warn: gboolean): gboolean{.
|
|
||||||
cdecl, dynlib: lib, importc: "pango_parse_variant".}
|
|
||||||
proc parse_weight*(str: cstring, weight: PWeight, warn: gboolean): gboolean{.
|
|
||||||
cdecl, dynlib: lib, importc: "pango_parse_weight".}
|
|
||||||
proc parse_stretch*(str: cstring, stretch: PStretch, warn: gboolean): gboolean{.
|
|
||||||
cdecl, dynlib: lib, importc: "pango_parse_stretch".}
|
|
||||||
proc get_sysconf_subdirectory*(): cstring{.cdecl, dynlib: lib,
|
|
||||||
importc: "pango_get_sysconf_subdirectory".}
|
|
||||||
proc get_lib_subdirectory*(): cstring{.cdecl, dynlib: lib,
|
|
||||||
importc: "pango_get_lib_subdirectory".}
|
|
||||||
proc log2vis_get_embedding_levels*(str: Pgunichar, len: int32,
|
|
||||||
pbase_dir: PDirection,
|
|
||||||
embedding_level_list: Pguint8): gboolean{.
|
|
||||||
cdecl, dynlib: lib, importc: "pango_log2vis_get_embedding_levels".}
|
|
||||||
proc get_mirror_char*(ch: gunichar, mirrored_ch: Pgunichar): gboolean{.cdecl,
|
|
||||||
dynlib: lib, importc: "pango_get_mirror_char".}
|
|
||||||
proc get_sample_string*(language: PLanguage): cstring{.cdecl,
|
|
||||||
dynlib: lib, importc: "pango_language_get_sample_string".}
|
|
||||||
|
|
@ -1,208 +0,0 @@
|
||||||
#*****************************************************************************
|
|
||||||
# * *
|
|
||||||
# * File: lauxlib.pas *
|
|
||||||
# * Authors: TeCGraf (C headers + actual Lua libraries) *
|
|
||||||
# * Lavergne Thomas (original translation to Pascal) *
|
|
||||||
# * Bram Kuijvenhoven (update to Lua 5.1.1 for FreePascal) *
|
|
||||||
# * Description: Lua auxiliary library *
|
|
||||||
# * *
|
|
||||||
# *****************************************************************************
|
|
||||||
#
|
|
||||||
#** $Id: lauxlib.h,v 1.59 2003/03/18 12:25:32 roberto Exp $
|
|
||||||
#** Auxiliary functions for building Lua libraries
|
|
||||||
#** See Copyright Notice in lua.h
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#** Translated to pascal by Lavergne Thomas
|
|
||||||
#** Notes :
|
|
||||||
#** - Pointers type was prefixed with 'P'
|
|
||||||
#** Bug reports :
|
|
||||||
#** - thomas.lavergne@laposte.net
|
|
||||||
#** In french or in english
|
|
||||||
#
|
|
||||||
|
|
||||||
import
|
|
||||||
lua
|
|
||||||
|
|
||||||
proc pushstring*(L: PState, s: string)
|
|
||||||
# compatibilty macros
|
|
||||||
proc getn*(L: PState, n: cint): cint
|
|
||||||
# calls lua_objlen
|
|
||||||
proc setn*(L: PState, t, n: cint)
|
|
||||||
# does nothing!
|
|
||||||
type
|
|
||||||
Treg*{.final.} = object
|
|
||||||
name*: cstring
|
|
||||||
func*: CFunction
|
|
||||||
|
|
||||||
Preg* = ptr Treg
|
|
||||||
|
|
||||||
|
|
||||||
{.push callConv: cdecl, dynlib: lua.LIB_NAME.}
|
|
||||||
{.push importc: "luaL_$1".}
|
|
||||||
|
|
||||||
proc openlib*(L: PState, libname: cstring, lr: Preg, nup: cint)
|
|
||||||
proc register*(L: PState, libname: cstring, lr: Preg)
|
|
||||||
|
|
||||||
proc getmetafield*(L: PState, obj: cint, e: cstring): cint
|
|
||||||
proc callmeta*(L: PState, obj: cint, e: cstring): cint
|
|
||||||
proc typerror*(L: PState, narg: cint, tname: cstring): cint
|
|
||||||
proc argerror*(L: PState, numarg: cint, extramsg: cstring): cint
|
|
||||||
proc checklstring*(L: PState, numArg: cint, len: ptr int): cstring
|
|
||||||
proc optlstring*(L: PState, numArg: cint, def: cstring, len: ptr cint): cstring
|
|
||||||
proc checknumber*(L: PState, numArg: cint): Number
|
|
||||||
proc optnumber*(L: PState, nArg: cint, def: Number): Number
|
|
||||||
proc checkinteger*(L: PState, numArg: cint): Integer
|
|
||||||
proc optinteger*(L: PState, nArg: cint, def: Integer): Integer
|
|
||||||
proc checkstack*(L: PState, sz: cint, msg: cstring)
|
|
||||||
proc checktype*(L: PState, narg, t: cint)
|
|
||||||
|
|
||||||
proc checkany*(L: PState, narg: cint)
|
|
||||||
proc newmetatable*(L: PState, tname: cstring): cint
|
|
||||||
|
|
||||||
proc checkudata*(L: PState, ud: cint, tname: cstring): Pointer
|
|
||||||
proc where*(L: PState, lvl: cint)
|
|
||||||
proc error*(L: PState, fmt: cstring): cint{.varargs.}
|
|
||||||
proc checkoption*(L: PState, narg: cint, def: cstring, lst: cstringArray): cint
|
|
||||||
|
|
||||||
proc unref*(L: PState, t, theref: cint)
|
|
||||||
proc loadfile*(L: PState, filename: cstring): cint
|
|
||||||
proc loadbuffer*(L: PState, buff: cstring, size: cint, name: cstring): cint
|
|
||||||
proc loadstring*(L: PState, s: cstring): cint
|
|
||||||
proc newstate*(): PState
|
|
||||||
|
|
||||||
{.pop.}
|
|
||||||
proc reference*(L: PState, t: cint): cint{.importc: "luaL_ref".}
|
|
||||||
|
|
||||||
{.pop.}
|
|
||||||
|
|
||||||
proc open*(): PState
|
|
||||||
# compatibility; moved from unit lua to lauxlib because it needs luaL_newstate
|
|
||||||
#
|
|
||||||
#** ===============================================================
|
|
||||||
#** some useful macros
|
|
||||||
#** ===============================================================
|
|
||||||
#
|
|
||||||
proc argcheck*(L: PState, cond: bool, numarg: cint, extramsg: cstring)
|
|
||||||
proc checkstring*(L: PState, n: cint): cstring
|
|
||||||
proc optstring*(L: PState, n: cint, d: cstring): cstring
|
|
||||||
proc checkint*(L: PState, n: cint): cint
|
|
||||||
proc checklong*(L: PState, n: cint): clong
|
|
||||||
proc optint*(L: PState, n: cint, d: float64): cint
|
|
||||||
proc optlong*(L: PState, n: cint, d: float64): clong
|
|
||||||
proc dofile*(L: PState, filename: cstring): cint
|
|
||||||
proc dostring*(L: PState, str: cstring): cint
|
|
||||||
proc getmetatable*(L: PState, tname: cstring)
|
|
||||||
# not translated:
|
|
||||||
# #define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))
|
|
||||||
#
|
|
||||||
#** =======================================================
|
|
||||||
#** Generic Buffer manipulation
|
|
||||||
#** =======================================================
|
|
||||||
#
|
|
||||||
const # note: this is just arbitrary, as it related to the BUFSIZ defined in stdio.h ...
|
|
||||||
BUFFERSIZE* = 4096
|
|
||||||
|
|
||||||
type
|
|
||||||
Buffer*{.final.} = object
|
|
||||||
p*: cstring # current position in buffer
|
|
||||||
lvl*: cint # number of strings in the stack (level)
|
|
||||||
L*: PState
|
|
||||||
buffer*: array[0..BUFFERSIZE - 1, Char] # warning: see note above about LUAL_BUFFERSIZE
|
|
||||||
|
|
||||||
PBuffer* = ptr Buffer
|
|
||||||
|
|
||||||
proc addchar*(B: PBuffer, c: Char)
|
|
||||||
# warning: see note above about LUAL_BUFFERSIZE
|
|
||||||
# compatibility only (alias for luaL_addchar)
|
|
||||||
proc putchar*(B: PBuffer, c: Char)
|
|
||||||
# warning: see note above about LUAL_BUFFERSIZE
|
|
||||||
proc addsize*(B: PBuffer, n: cint)
|
|
||||||
|
|
||||||
{.push callConv: cdecl, dynlib: lua.LIB_NAME, importc: "luaL_$1".}
|
|
||||||
proc buffinit*(L: PState, B: PBuffer)
|
|
||||||
proc prepbuffer*(B: PBuffer): cstring
|
|
||||||
proc addlstring*(B: PBuffer, s: cstring, L: cint)
|
|
||||||
proc addstring*(B: PBuffer, s: cstring)
|
|
||||||
proc addvalue*(B: PBuffer)
|
|
||||||
proc pushresult*(B: PBuffer)
|
|
||||||
proc gsub*(L: PState, s, p, r: cstring): cstring
|
|
||||||
proc findtable*(L: PState, idx: cint, fname: cstring, szhint: cint): cstring
|
|
||||||
# compatibility with ref system
|
|
||||||
# pre-defined references
|
|
||||||
{.pop.}
|
|
||||||
|
|
||||||
const
|
|
||||||
NOREF* = - 2
|
|
||||||
REFNIL* = - 1
|
|
||||||
|
|
||||||
proc unref*(L: PState, theref: cint)
|
|
||||||
proc getref*(L: PState, theref: cint)
|
|
||||||
#
|
|
||||||
#** Compatibility macros and functions
|
|
||||||
#
|
|
||||||
# implementation
|
|
||||||
|
|
||||||
proc pushstring(L: PState, s: string) =
|
|
||||||
pushlstring(L, cstring(s), s.len.cint)
|
|
||||||
|
|
||||||
proc getn(L: PState, n: cint): cint =
|
|
||||||
Result = objlen(L, n)
|
|
||||||
|
|
||||||
proc setn(L: PState, t, n: cint) =
|
|
||||||
# does nothing as this operation is deprecated
|
|
||||||
nil
|
|
||||||
|
|
||||||
proc open(): PState =
|
|
||||||
Result = newstate()
|
|
||||||
|
|
||||||
proc dofile(L: PState, filename: cstring): cint =
|
|
||||||
Result = loadfile(L, filename)
|
|
||||||
if Result == 0: Result = pcall(L, 0, MULTRET, 0)
|
|
||||||
|
|
||||||
proc dostring(L: PState, str: cstring): cint =
|
|
||||||
Result = loadstring(L, str)
|
|
||||||
if Result == 0: Result = pcall(L, 0, MULTRET, 0)
|
|
||||||
|
|
||||||
proc getmetatable(L: PState, tname: cstring) =
|
|
||||||
getfield(L, REGISTRYINDEX, tname)
|
|
||||||
|
|
||||||
proc argcheck(L: PState, cond: bool, numarg: cint, extramsg: cstring) =
|
|
||||||
if not cond:
|
|
||||||
discard argerror(L, numarg, extramsg)
|
|
||||||
|
|
||||||
proc checkstring(L: PState, n: cint): cstring =
|
|
||||||
Result = checklstring(L, n, nil)
|
|
||||||
|
|
||||||
proc optstring(L: PState, n: cint, d: cstring): cstring =
|
|
||||||
Result = optlstring(L, n, d, nil)
|
|
||||||
|
|
||||||
proc checkint(L: PState, n: cint): cint =
|
|
||||||
Result = cint(checknumber(L, n))
|
|
||||||
|
|
||||||
proc checklong(L: PState, n: cint): clong =
|
|
||||||
Result = int32(ToInt(checknumber(L, n)))
|
|
||||||
|
|
||||||
proc optint(L: PState, n: cint, d: float64): cint =
|
|
||||||
Result = optnumber(L, n, d).cint
|
|
||||||
|
|
||||||
proc optlong(L: PState, n: cint, d: float64): clong =
|
|
||||||
Result = int32(ToInt(optnumber(L, n, d)))
|
|
||||||
|
|
||||||
proc addchar(B: PBuffer, c: Char) =
|
|
||||||
if cast[int](addr((B.p))) < (cast[int](addr((B.buffer[0]))) + BUFFERSIZE):
|
|
||||||
discard prepbuffer(B)
|
|
||||||
B.p[1] = c
|
|
||||||
B.p = cast[cstring](cast[int](B.p) + 1)
|
|
||||||
|
|
||||||
proc putchar(B: PBuffer, c: Char) =
|
|
||||||
addchar(B, c)
|
|
||||||
|
|
||||||
proc addsize(B: PBuffer, n: cint) =
|
|
||||||
B.p = cast[cstring](cast[int](B.p) + n)
|
|
||||||
|
|
||||||
proc unref(L: PState, theref: cint) =
|
|
||||||
unref(L, REGISTRYINDEX, theref)
|
|
||||||
|
|
||||||
proc getref(L: PState, theref: cint) =
|
|
||||||
rawgeti(L, REGISTRYINDEX, theref)
|
|
||||||
|
|
@ -1,364 +0,0 @@
|
||||||
#*****************************************************************************
|
|
||||||
# * *
|
|
||||||
# * File: lua.pas *
|
|
||||||
# * Authors: TeCGraf (C headers + actual Lua libraries) *
|
|
||||||
# * Lavergne Thomas (original translation to Pascal) *
|
|
||||||
# * Bram Kuijvenhoven (update to Lua 5.1.1 for FreePascal) *
|
|
||||||
# * Description: Basic Lua library *
|
|
||||||
# * *
|
|
||||||
# *****************************************************************************
|
|
||||||
#
|
|
||||||
#** $Id: lua.h,v 1.175 2003/03/18 12:31:39 roberto Exp $
|
|
||||||
#** Lua - An Extensible Extension Language
|
|
||||||
#** TeCGraf: Computer Graphics Technology Group, PUC-Rio, Brazil
|
|
||||||
#** http://www.lua.org mailto:info@lua.org
|
|
||||||
#** See Copyright Notice at the end of this file
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#** Updated to Lua 5.1.1 by Bram Kuijvenhoven (bram at kuijvenhoven dot net),
|
|
||||||
#** Hexis BV (http://www.hexis.nl), the Netherlands
|
|
||||||
#** Notes:
|
|
||||||
#** - Only tested with FPC (FreePascal Compiler)
|
|
||||||
#** - Using LuaBinaries styled DLL/SO names, which include version names
|
|
||||||
#** - LUA_YIELD was suffixed by '_' for avoiding name collision
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#** Translated to pascal by Lavergne Thomas
|
|
||||||
#** Notes :
|
|
||||||
#** - Pointers type was prefixed with 'P'
|
|
||||||
#** - lua_upvalueindex constant was transformed to function
|
|
||||||
#** - Some compatibility function was isolated because with it you must have
|
|
||||||
#** lualib.
|
|
||||||
#** - LUA_VERSION was suffixed by '_' for avoiding name collision.
|
|
||||||
#** Bug reports :
|
|
||||||
#** - thomas.lavergne@laposte.net
|
|
||||||
#** In french or in english
|
|
||||||
#
|
|
||||||
|
|
||||||
when defined(useLuajit):
|
|
||||||
when defined(MACOSX):
|
|
||||||
const
|
|
||||||
NAME* = "libluajit.dylib"
|
|
||||||
LIB_NAME* = "libluajit.dylib"
|
|
||||||
elif defined(UNIX):
|
|
||||||
const
|
|
||||||
NAME* = "libluajit.so(|.0)"
|
|
||||||
LIB_NAME* = "libluajit.so(|.0)"
|
|
||||||
else:
|
|
||||||
const
|
|
||||||
NAME* = "luajit.dll"
|
|
||||||
LIB_NAME* = "luajit.dll"
|
|
||||||
else:
|
|
||||||
when defined(MACOSX):
|
|
||||||
const
|
|
||||||
NAME* = "liblua(|5.1|5.0).dylib"
|
|
||||||
LIB_NAME* = "liblua(|5.1|5.0).dylib"
|
|
||||||
elif defined(UNIX):
|
|
||||||
const
|
|
||||||
NAME* = "liblua(|5.1|5.0).so(|.0)"
|
|
||||||
LIB_NAME* = "liblua(|5.1|5.0).so(|.0)"
|
|
||||||
else:
|
|
||||||
const
|
|
||||||
NAME* = "lua(|5.1|5.0).dll"
|
|
||||||
LIB_NAME* = "lua(|5.1|5.0).dll"
|
|
||||||
|
|
||||||
const
|
|
||||||
VERSION* = "Lua 5.1"
|
|
||||||
RELEASE* = "Lua 5.1.1"
|
|
||||||
VERSION_NUM* = 501
|
|
||||||
COPYRIGHT* = "Copyright (C) 1994-2006 Lua.org, PUC-Rio"
|
|
||||||
AUTHORS* = "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
|
|
||||||
# option for multiple returns in `lua_pcall' and `lua_call'
|
|
||||||
MULTRET* = - 1 #
|
|
||||||
#** pseudo-indices
|
|
||||||
#
|
|
||||||
REGISTRYINDEX* = - 10000
|
|
||||||
ENVIRONINDEX* = - 10001
|
|
||||||
GLOBALSINDEX* = - 10002
|
|
||||||
|
|
||||||
proc upvalueindex*(I: cint): cint
|
|
||||||
const # thread status; 0 is OK
|
|
||||||
constYIELD* = 1
|
|
||||||
ERRRUN* = 2
|
|
||||||
ERRSYNTAX* = 3
|
|
||||||
ERRMEM* = 4
|
|
||||||
ERRERR* = 5
|
|
||||||
|
|
||||||
type
|
|
||||||
PState* = Pointer
|
|
||||||
CFunction* = proc (L: PState): cint{.cdecl.}
|
|
||||||
|
|
||||||
#
|
|
||||||
#** functions that read/write blocks when loading/dumping Lua chunks
|
|
||||||
#
|
|
||||||
|
|
||||||
type
|
|
||||||
Reader* = proc (L: PState, ud: Pointer, sz: ptr cint): cstring{.cdecl.}
|
|
||||||
Writer* = proc (L: PState, p: Pointer, sz: cint, ud: Pointer): cint{.cdecl.}
|
|
||||||
Alloc* = proc (ud, theptr: Pointer, osize, nsize: cint){.cdecl.}
|
|
||||||
|
|
||||||
const
|
|
||||||
TNONE* = - 1
|
|
||||||
TNIL* = 0
|
|
||||||
TBOOLEAN* = 1
|
|
||||||
TLIGHTUSERDATA* = 2
|
|
||||||
TNUMBER* = 3
|
|
||||||
TSTRING* = 4
|
|
||||||
TTABLE* = 5
|
|
||||||
TFUNCTION* = 6
|
|
||||||
TUSERDATA* = 7
|
|
||||||
TTHREAD* = 8 # minimum Lua stack available to a C function
|
|
||||||
MINSTACK* = 20
|
|
||||||
|
|
||||||
type # Type of Numbers in Lua
|
|
||||||
Number* = float
|
|
||||||
Integer* = cint
|
|
||||||
|
|
||||||
{.pragma: ilua, importc: "lua_$1".}
|
|
||||||
|
|
||||||
{.push callConv: cdecl, dynlib: LibName.}
|
|
||||||
#{.push importc: "lua_$1".}
|
|
||||||
|
|
||||||
proc newstate*(f: Alloc, ud: Pointer): PState {.ilua.}
|
|
||||||
|
|
||||||
proc close*(L: PState){.ilua.}
|
|
||||||
proc newthread*(L: PState): PState{.ilua.}
|
|
||||||
proc atpanic*(L: PState, panicf: CFunction): CFunction{.ilua.}
|
|
||||||
|
|
||||||
proc gettop*(L: PState): cint{.ilua.}
|
|
||||||
proc settop*(L: PState, idx: cint){.ilua.}
|
|
||||||
proc pushvalue*(L: PState, Idx: cint){.ilua.}
|
|
||||||
proc remove*(L: PState, idx: cint){.ilua.}
|
|
||||||
proc insert*(L: PState, idx: cint){.ilua.}
|
|
||||||
proc replace*(L: PState, idx: cint){.ilua.}
|
|
||||||
proc checkstack*(L: PState, sz: cint): cint{.ilua.}
|
|
||||||
proc xmove*(`from`, `to`: PState, n: cint){.ilua.}
|
|
||||||
proc isnumber*(L: PState, idx: cint): cint{.ilua.}
|
|
||||||
proc isstring*(L: PState, idx: cint): cint{.ilua.}
|
|
||||||
proc iscfunction*(L: PState, idx: cint): cint{.ilua.}
|
|
||||||
proc isuserdata*(L: PState, idx: cint): cint{.ilua.}
|
|
||||||
proc luatype*(L: PState, idx: cint): cint{.importc: "lua_type".}
|
|
||||||
proc typename*(L: PState, tp: cint): cstring{.ilua.}
|
|
||||||
proc equal*(L: PState, idx1, idx2: cint): cint{.ilua.}
|
|
||||||
proc rawequal*(L: PState, idx1, idx2: cint): cint{.ilua.}
|
|
||||||
proc lessthan*(L: PState, idx1, idx2: cint): cint{.ilua.}
|
|
||||||
proc tonumber*(L: PState, idx: cint): Number{.ilua.}
|
|
||||||
proc tointeger*(L: PState, idx: cint): Integer{.ilua.}
|
|
||||||
proc toboolean*(L: PState, idx: cint): cint{.ilua.}
|
|
||||||
proc tolstring*(L: PState, idx: cint, length: ptr cint): cstring{.ilua.}
|
|
||||||
proc objlen*(L: PState, idx: cint): cint{.ilua.}
|
|
||||||
proc tocfunction*(L: PState, idx: cint): CFunction{.ilua.}
|
|
||||||
proc touserdata*(L: PState, idx: cint): Pointer{.ilua.}
|
|
||||||
proc tothread*(L: PState, idx: cint): PState{.ilua.}
|
|
||||||
proc topointer*(L: PState, idx: cint): Pointer{.ilua.}
|
|
||||||
proc pushnil*(L: PState){.ilua.}
|
|
||||||
proc pushnumber*(L: PState, n: Number){.ilua.}
|
|
||||||
proc pushinteger*(L: PState, n: Integer){.ilua.}
|
|
||||||
proc pushlstring*(L: PState, s: cstring, len: cint){.ilua.}
|
|
||||||
proc pushstring*(L: PState, s: cstring){.ilua.}
|
|
||||||
proc pushvfstring*(L: PState, fmt: cstring, argp: Pointer): cstring{.ilua.}
|
|
||||||
proc pushfstring*(L: PState, fmt: cstring): cstring{.varargs,ilua.}
|
|
||||||
proc pushcclosure*(L: PState, fn: CFunction, n: cint){.ilua.}
|
|
||||||
proc pushboolean*(L: PState, b: cint){.ilua.}
|
|
||||||
proc pushlightuserdata*(L: PState, p: Pointer){.ilua.}
|
|
||||||
proc pushthread*(L: PState){.ilua.}
|
|
||||||
proc gettable*(L: PState, idx: cint){.ilua.}
|
|
||||||
proc getfield*(L: Pstate, idx: cint, k: cstring){.ilua.}
|
|
||||||
proc rawget*(L: PState, idx: cint){.ilua.}
|
|
||||||
proc rawgeti*(L: PState, idx, n: cint){.ilua.}
|
|
||||||
proc createtable*(L: PState, narr, nrec: cint){.ilua.}
|
|
||||||
proc newuserdata*(L: PState, sz: cint): Pointer{.ilua.}
|
|
||||||
proc getmetatable*(L: PState, objindex: cint): cint{.ilua.}
|
|
||||||
proc getfenv*(L: PState, idx: cint){.ilua.}
|
|
||||||
proc settable*(L: PState, idx: cint){.ilua.}
|
|
||||||
proc setfield*(L: PState, idx: cint, k: cstring){.ilua.}
|
|
||||||
proc rawset*(L: PState, idx: cint){.ilua.}
|
|
||||||
proc rawseti*(L: PState, idx, n: cint){.ilua.}
|
|
||||||
proc setmetatable*(L: PState, objindex: cint): cint{.ilua.}
|
|
||||||
proc setfenv*(L: PState, idx: cint): cint{.ilua.}
|
|
||||||
proc call*(L: PState, nargs, nresults: cint){.ilua.}
|
|
||||||
proc pcall*(L: PState, nargs, nresults, errf: cint): cint{.ilua.}
|
|
||||||
proc cpcall*(L: PState, func: CFunction, ud: Pointer): cint{.ilua.}
|
|
||||||
proc load*(L: PState, reader: Reader, dt: Pointer, chunkname: cstring): cint{.ilua.}
|
|
||||||
proc dump*(L: PState, writer: Writer, data: Pointer): cint{.ilua.}
|
|
||||||
proc luayield*(L: PState, nresults: cint): cint{.importc: "lua_yield".}
|
|
||||||
proc resume*(L: PState, narg: cint): cint{.ilua.}
|
|
||||||
proc status*(L: PState): cint{.ilua.}
|
|
||||||
proc gc*(L: PState, what, data: cint): cint{.ilua.}
|
|
||||||
proc error*(L: PState): cint{.ilua.}
|
|
||||||
proc next*(L: PState, idx: cint): cint{.ilua.}
|
|
||||||
proc concat*(L: PState, n: cint){.ilua.}
|
|
||||||
proc getallocf*(L: PState, ud: ptr Pointer): Alloc{.ilua.}
|
|
||||||
proc setallocf*(L: PState, f: Alloc, ud: Pointer){.ilua.}
|
|
||||||
{.pop.}
|
|
||||||
|
|
||||||
#
|
|
||||||
#** Garbage-collection functions and options
|
|
||||||
#
|
|
||||||
|
|
||||||
const
|
|
||||||
GCSTOP* = 0
|
|
||||||
GCRESTART* = 1
|
|
||||||
GCCOLLECT* = 2
|
|
||||||
GCCOUNT* = 3
|
|
||||||
GCCOUNTB* = 4
|
|
||||||
GCSTEP* = 5
|
|
||||||
GCSETPAUSE* = 6
|
|
||||||
GCSETSTEPMUL* = 7
|
|
||||||
|
|
||||||
#
|
|
||||||
#** ===============================================================
|
|
||||||
#** some useful macros
|
|
||||||
#** ===============================================================
|
|
||||||
#
|
|
||||||
|
|
||||||
proc pop*(L: PState, n: cint)
|
|
||||||
proc newtable*(L: Pstate)
|
|
||||||
proc register*(L: PState, n: cstring, f: CFunction)
|
|
||||||
proc pushcfunction*(L: PState, f: CFunction)
|
|
||||||
proc strlen*(L: Pstate, i: cint): cint
|
|
||||||
proc isfunction*(L: PState, n: cint): bool
|
|
||||||
proc istable*(L: PState, n: cint): bool
|
|
||||||
proc islightuserdata*(L: PState, n: cint): bool
|
|
||||||
proc isnil*(L: PState, n: cint): bool
|
|
||||||
proc isboolean*(L: PState, n: cint): bool
|
|
||||||
proc isthread*(L: PState, n: cint): bool
|
|
||||||
proc isnone*(L: PState, n: cint): bool
|
|
||||||
proc isnoneornil*(L: PState, n: cint): bool
|
|
||||||
proc pushliteral*(L: PState, s: cstring)
|
|
||||||
proc setglobal*(L: PState, s: cstring)
|
|
||||||
proc getglobal*(L: PState, s: cstring)
|
|
||||||
proc tostring*(L: PState, i: cint): cstring
|
|
||||||
#
|
|
||||||
#** compatibility macros and functions
|
|
||||||
#
|
|
||||||
|
|
||||||
proc getregistry*(L: PState)
|
|
||||||
proc getgccount*(L: PState): cint
|
|
||||||
type
|
|
||||||
Chunkreader* = Reader
|
|
||||||
Chunkwriter* = Writer
|
|
||||||
|
|
||||||
#
|
|
||||||
#** ======================================================================
|
|
||||||
#** Debug API
|
|
||||||
#** ======================================================================
|
|
||||||
#
|
|
||||||
|
|
||||||
const
|
|
||||||
HOOKCALL* = 0
|
|
||||||
HOOKRET* = 1
|
|
||||||
HOOKLINE* = 2
|
|
||||||
HOOKCOUNT* = 3
|
|
||||||
HOOKTAILRET* = 4
|
|
||||||
|
|
||||||
const
|
|
||||||
MASKCALL* = 1 shl Ord(HOOKCALL)
|
|
||||||
MASKRET* = 1 shl Ord(HOOKRET)
|
|
||||||
MASKLINE* = 1 shl Ord(HOOKLINE)
|
|
||||||
MASKCOUNT* = 1 shl Ord(HOOKCOUNT)
|
|
||||||
|
|
||||||
const
|
|
||||||
IDSIZE* = 60
|
|
||||||
|
|
||||||
type
|
|
||||||
TDebug*{.final.} = object # activation record
|
|
||||||
event*: cint
|
|
||||||
name*: cstring # (n)
|
|
||||||
namewhat*: cstring # (n) `global', `local', `field', `method'
|
|
||||||
what*: cstring # (S) `Lua', `C', `main', `tail'
|
|
||||||
source*: cstring # (S)
|
|
||||||
currentline*: cint # (l)
|
|
||||||
nups*: cint # (u) number of upvalues
|
|
||||||
linedefined*: cint # (S)
|
|
||||||
lastlinedefined*: cint # (S)
|
|
||||||
short_src*: array[0.. <IDSIZE, Char] # (S) \
|
|
||||||
# private part
|
|
||||||
i_ci*: cint # active function
|
|
||||||
|
|
||||||
PDebug* = ptr TDebug
|
|
||||||
Hook* = proc (L: PState, ar: PDebug){.cdecl.}
|
|
||||||
|
|
||||||
#
|
|
||||||
#** ======================================================================
|
|
||||||
#** Debug API
|
|
||||||
#** ======================================================================
|
|
||||||
#
|
|
||||||
|
|
||||||
{.push callConv: cdecl, dynlib: lua.LIB_NAME.}
|
|
||||||
|
|
||||||
proc getstack*(L: PState, level: cint, ar: PDebug): cint{.ilua.}
|
|
||||||
proc getinfo*(L: PState, what: cstring, ar: PDebug): cint{.ilua.}
|
|
||||||
proc getlocal*(L: PState, ar: PDebug, n: cint): cstring{.ilua.}
|
|
||||||
proc setlocal*(L: PState, ar: PDebug, n: cint): cstring{.ilua.}
|
|
||||||
proc getupvalue*(L: PState, funcindex: cint, n: cint): cstring{.ilua.}
|
|
||||||
proc setupvalue*(L: PState, funcindex: cint, n: cint): cstring{.ilua.}
|
|
||||||
proc sethook*(L: PState, func: Hook, mask: cint, count: cint): cint{.ilua.}
|
|
||||||
proc gethook*(L: PState): Hook{.ilua.}
|
|
||||||
proc gethookmask*(L: PState): cint{.ilua.}
|
|
||||||
proc gethookcount*(L: PState): cint{.ilua.}
|
|
||||||
|
|
||||||
{.pop.}
|
|
||||||
|
|
||||||
# implementation
|
|
||||||
|
|
||||||
proc upvalueindex(I: cint): cint =
|
|
||||||
Result = GLOBALSINDEX - i
|
|
||||||
|
|
||||||
proc pop(L: PState, n: cint) =
|
|
||||||
settop(L, - n - 1)
|
|
||||||
|
|
||||||
proc newtable(L: PState) =
|
|
||||||
createtable(L, 0, 0)
|
|
||||||
|
|
||||||
proc register(L: PState, n: cstring, f: CFunction) =
|
|
||||||
pushcfunction(L, f)
|
|
||||||
setglobal(L, n)
|
|
||||||
|
|
||||||
proc pushcfunction(L: PState, f: CFunction) =
|
|
||||||
pushcclosure(L, f, 0)
|
|
||||||
|
|
||||||
proc strlen(L: PState, i: cint): cint =
|
|
||||||
Result = objlen(L, i)
|
|
||||||
|
|
||||||
proc isfunction(L: PState, n: cint): bool =
|
|
||||||
Result = luatype(L, n) == TFUNCTION
|
|
||||||
|
|
||||||
proc istable(L: PState, n: cint): bool =
|
|
||||||
Result = luatype(L, n) == TTABLE
|
|
||||||
|
|
||||||
proc islightuserdata(L: PState, n: cint): bool =
|
|
||||||
Result = luatype(L, n) == TLIGHTUSERDATA
|
|
||||||
|
|
||||||
proc isnil(L: PState, n: cint): bool =
|
|
||||||
Result = luatype(L, n) == TNIL
|
|
||||||
|
|
||||||
proc isboolean(L: PState, n: cint): bool =
|
|
||||||
Result = luatype(L, n) == TBOOLEAN
|
|
||||||
|
|
||||||
proc isthread(L: PState, n: cint): bool =
|
|
||||||
Result = luatype(L, n) == TTHREAD
|
|
||||||
|
|
||||||
proc isnone(L: PState, n: cint): bool =
|
|
||||||
Result = luatype(L, n) == TNONE
|
|
||||||
|
|
||||||
proc isnoneornil(L: PState, n: cint): bool =
|
|
||||||
Result = luatype(L, n) <= 0
|
|
||||||
|
|
||||||
proc pushliteral(L: PState, s: cstring) =
|
|
||||||
pushlstring(L, s, s.len.cint)
|
|
||||||
|
|
||||||
proc setglobal(L: PState, s: cstring) =
|
|
||||||
setfield(L, GLOBALSINDEX, s)
|
|
||||||
|
|
||||||
proc getglobal(L: PState, s: cstring) =
|
|
||||||
getfield(L, GLOBALSINDEX, s)
|
|
||||||
|
|
||||||
proc tostring(L: PState, i: cint): cstring =
|
|
||||||
Result = tolstring(L, i, nil)
|
|
||||||
|
|
||||||
proc getregistry(L: PState) =
|
|
||||||
pushvalue(L, REGISTRYINDEX)
|
|
||||||
|
|
||||||
proc getgccount(L: PState): cint =
|
|
||||||
Result = gc(L, GCCOUNT, 0)
|
|
||||||
|
|
@ -1,64 +0,0 @@
|
||||||
#*****************************************************************************
|
|
||||||
# * *
|
|
||||||
# * File: lualib.pas *
|
|
||||||
# * Authors: TeCGraf (C headers + actual Lua libraries) *
|
|
||||||
# * Lavergne Thomas (original translation to Pascal) *
|
|
||||||
# * Bram Kuijvenhoven (update to Lua 5.1.1 for FreePascal) *
|
|
||||||
# * Description: Standard Lua libraries *
|
|
||||||
# * *
|
|
||||||
# *****************************************************************************
|
|
||||||
#
|
|
||||||
#** $Id: lualib.h,v 1.28 2003/03/18 12:24:26 roberto Exp $
|
|
||||||
#** Lua standard libraries
|
|
||||||
#** See Copyright Notice in lua.h
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#** Translated to pascal by Lavergne Thomas
|
|
||||||
#** Bug reports :
|
|
||||||
#** - thomas.lavergne@laposte.net
|
|
||||||
#** In french or in english
|
|
||||||
#
|
|
||||||
|
|
||||||
import
|
|
||||||
lua
|
|
||||||
|
|
||||||
const
|
|
||||||
COLIBNAME* = "coroutine"
|
|
||||||
TABLIBNAME* = "table"
|
|
||||||
IOLIBNAME* = "io"
|
|
||||||
OSLIBNAME* = "os"
|
|
||||||
STRLINAME* = "string"
|
|
||||||
MATHLIBNAME* = "math"
|
|
||||||
DBLIBNAME* = "debug"
|
|
||||||
LOADLIBNAME* = "package"
|
|
||||||
|
|
||||||
{.pragma: ilua, importc: "lua$1".}
|
|
||||||
|
|
||||||
{.push callConv: cdecl, dynlib: lua.LIB_NAME.}
|
|
||||||
proc open_base*(L: PState): cint{.ilua.}
|
|
||||||
proc open_table*(L: PState): cint{.ilua.}
|
|
||||||
proc open_io*(L: PState): cint{.ilua.}
|
|
||||||
proc open_string*(L: PState): cint{.ilua.}
|
|
||||||
proc open_math*(L: PState): cint{.ilua.}
|
|
||||||
proc open_debug*(L: PState): cint{.ilua.}
|
|
||||||
proc open_package*(L: PState): cint{.ilua.}
|
|
||||||
proc openlibs*(L: PState){.importc: "luaL_openlibs".}
|
|
||||||
{.pop.}
|
|
||||||
|
|
||||||
proc baselibopen*(L: PState): Bool =
|
|
||||||
open_base(L) != 0'i32
|
|
||||||
|
|
||||||
proc tablibopen*(L: PState): Bool =
|
|
||||||
open_table(L) != 0'i32
|
|
||||||
|
|
||||||
proc iolibopen*(L: PState): Bool =
|
|
||||||
open_io(L) != 0'i32
|
|
||||||
|
|
||||||
proc strlibopen*(L: PState): Bool =
|
|
||||||
open_string(L) != 0'i32
|
|
||||||
|
|
||||||
proc mathlibopen*(L: PState): Bool =
|
|
||||||
open_math(L) != 0'i32
|
|
||||||
|
|
||||||
proc dblibopen*(L: PState): Bool =
|
|
||||||
open_debug(L) != 0'i32
|
|
||||||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -1,335 +0,0 @@
|
||||||
#
|
|
||||||
#
|
|
||||||
# Adaption of the delphi3d.net OpenGL units to FreePascal
|
|
||||||
# Sebastian Guenther (sg@freepascal.org) in 2002
|
|
||||||
# These units are free to use
|
|
||||||
#******************************************************************************
|
|
||||||
# Converted to Delphi by Tom Nuydens (tom@delphi3d.net)
|
|
||||||
# For the latest updates, visit Delphi3D: http://www.delphi3d.net
|
|
||||||
#******************************************************************************
|
|
||||||
|
|
||||||
import
|
|
||||||
GL
|
|
||||||
|
|
||||||
when defined(windows):
|
|
||||||
{.push, callconv: stdcall.}
|
|
||||||
else:
|
|
||||||
{.push, callconv: cdecl.}
|
|
||||||
|
|
||||||
when defined(windows):
|
|
||||||
const
|
|
||||||
dllname = "glu32.dll"
|
|
||||||
elif defined(macosx):
|
|
||||||
const
|
|
||||||
dllname = "/System/Library/Frameworks/OpenGL.framework/Libraries/libGLU.dylib"
|
|
||||||
else:
|
|
||||||
const
|
|
||||||
dllname = "libGLU.so.1"
|
|
||||||
type
|
|
||||||
TViewPortArray* = array[0..3, TGLint]
|
|
||||||
T16dArray* = array[0..15, TGLdouble]
|
|
||||||
TCallBack* = proc ()
|
|
||||||
T3dArray* = array[0..2, TGLdouble]
|
|
||||||
T4pArray* = array[0..3, Pointer]
|
|
||||||
T4fArray* = array[0..3, TGLfloat]
|
|
||||||
PPointer* = ptr Pointer
|
|
||||||
|
|
||||||
type
|
|
||||||
GLUnurbs*{.final.} = object
|
|
||||||
PGLUnurbs* = ptr GLUnurbs
|
|
||||||
GLUquadric*{.final.} = object
|
|
||||||
PGLUquadric* = ptr GLUquadric
|
|
||||||
GLUtesselator*{.final.} = object
|
|
||||||
PGLUtesselator* = ptr GLUtesselator # backwards compatibility:
|
|
||||||
GLUnurbsObj* = GLUnurbs
|
|
||||||
PGLUnurbsObj* = PGLUnurbs
|
|
||||||
GLUquadricObj* = GLUquadric
|
|
||||||
PGLUquadricObj* = PGLUquadric
|
|
||||||
GLUtesselatorObj* = GLUtesselator
|
|
||||||
PGLUtesselatorObj* = PGLUtesselator
|
|
||||||
GLUtriangulatorObj* = GLUtesselator
|
|
||||||
PGLUtriangulatorObj* = PGLUtesselator
|
|
||||||
TGLUnurbs* = GLUnurbs
|
|
||||||
TGLUquadric* = GLUquadric
|
|
||||||
TGLUtesselator* = GLUtesselator
|
|
||||||
TGLUnurbsObj* = GLUnurbsObj
|
|
||||||
TGLUquadricObj* = GLUquadricObj
|
|
||||||
TGLUtesselatorObj* = GLUtesselatorObj
|
|
||||||
TGLUtriangulatorObj* = GLUtriangulatorObj
|
|
||||||
|
|
||||||
proc gluErrorString*(errCode: TGLenum): cstring{.dynlib: dllname,
|
|
||||||
importc: "gluErrorString".}
|
|
||||||
proc gluErrorUnicodeStringEXT*(errCode: TGLenum): ptr int16{.dynlib: dllname,
|
|
||||||
importc: "gluErrorUnicodeStringEXT".}
|
|
||||||
proc gluGetString*(name: TGLenum): cstring{.dynlib: dllname,
|
|
||||||
importc: "gluGetString".}
|
|
||||||
proc gluOrtho2D*(left, right, bottom, top: TGLdouble){.dynlib: dllname,
|
|
||||||
importc: "gluOrtho2D".}
|
|
||||||
proc gluPerspective*(fovy, aspect, zNear, zFar: TGLdouble){.dynlib: dllname,
|
|
||||||
importc: "gluPerspective".}
|
|
||||||
proc gluPickMatrix*(x, y, width, height: TGLdouble, viewport: var TViewPortArray){.
|
|
||||||
dynlib: dllname, importc: "gluPickMatrix".}
|
|
||||||
proc gluLookAt*(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz: TGLdouble){.
|
|
||||||
dynlib: dllname, importc: "gluLookAt".}
|
|
||||||
proc gluProject*(objx, objy, objz: TGLdouble,
|
|
||||||
modelMatrix, projMatrix: var T16dArray,
|
|
||||||
viewport: var TViewPortArray, winx, winy, winz: PGLdouble): int{.
|
|
||||||
dynlib: dllname, importc: "gluProject".}
|
|
||||||
proc gluUnProject*(winx, winy, winz: TGLdouble,
|
|
||||||
modelMatrix, projMatrix: var T16dArray,
|
|
||||||
viewport: var TViewPortArray, objx, objy, objz: PGLdouble): int{.
|
|
||||||
dynlib: dllname, importc: "gluUnProject".}
|
|
||||||
proc gluScaleImage*(format: TGLenum, widthin, heightin: TGLint, typein: TGLenum,
|
|
||||||
datain: Pointer, widthout, heightout: TGLint,
|
|
||||||
typeout: TGLenum, dataout: Pointer): int{.dynlib: dllname,
|
|
||||||
importc: "gluScaleImage".}
|
|
||||||
proc gluBuild1DMipmaps*(target: TGLenum, components, width: TGLint,
|
|
||||||
format, atype: TGLenum, data: Pointer): int{.
|
|
||||||
dynlib: dllname, importc: "gluBuild1DMipmaps".}
|
|
||||||
proc gluBuild2DMipmaps*(target: TGLenum, components, width, height: TGLint,
|
|
||||||
format, atype: TGLenum, data: Pointer): int{.
|
|
||||||
dynlib: dllname, importc: "gluBuild2DMipmaps".}
|
|
||||||
proc gluNewQuadric*(): PGLUquadric{.dynlib: dllname, importc: "gluNewQuadric".}
|
|
||||||
proc gluDeleteQuadric*(state: PGLUquadric){.dynlib: dllname,
|
|
||||||
importc: "gluDeleteQuadric".}
|
|
||||||
proc gluQuadricNormals*(quadObject: PGLUquadric, normals: TGLenum){.
|
|
||||||
dynlib: dllname, importc: "gluQuadricNormals".}
|
|
||||||
proc gluQuadricTexture*(quadObject: PGLUquadric, textureCoords: TGLboolean){.
|
|
||||||
dynlib: dllname, importc: "gluQuadricTexture".}
|
|
||||||
proc gluQuadricOrientation*(quadObject: PGLUquadric, orientation: TGLenum){.
|
|
||||||
dynlib: dllname, importc: "gluQuadricOrientation".}
|
|
||||||
proc gluQuadricDrawStyle*(quadObject: PGLUquadric, drawStyle: TGLenum){.
|
|
||||||
dynlib: dllname, importc: "gluQuadricDrawStyle".}
|
|
||||||
proc gluCylinder*(qobj: PGLUquadric, baseRadius, topRadius, height: TGLdouble,
|
|
||||||
slices, stacks: TGLint){.dynlib: dllname,
|
|
||||||
importc: "gluCylinder".}
|
|
||||||
proc gluDisk*(qobj: PGLUquadric, innerRadius, outerRadius: TGLdouble,
|
|
||||||
slices, loops: TGLint){.dynlib: dllname, importc: "gluDisk".}
|
|
||||||
proc gluPartialDisk*(qobj: PGLUquadric, innerRadius, outerRadius: TGLdouble,
|
|
||||||
slices, loops: TGLint, startAngle, sweepAngle: TGLdouble){.
|
|
||||||
dynlib: dllname, importc: "gluPartialDisk".}
|
|
||||||
proc gluSphere*(qobj: PGLuquadric, radius: TGLdouble, slices, stacks: TGLint){.
|
|
||||||
dynlib: dllname, importc: "gluSphere".}
|
|
||||||
proc gluQuadricCallback*(qobj: PGLUquadric, which: TGLenum, fn: TCallBack){.
|
|
||||||
dynlib: dllname, importc: "gluQuadricCallback".}
|
|
||||||
proc gluNewTess*(): PGLUtesselator{.dynlib: dllname, importc: "gluNewTess".}
|
|
||||||
proc gluDeleteTess*(tess: PGLUtesselator){.dynlib: dllname,
|
|
||||||
importc: "gluDeleteTess".}
|
|
||||||
proc gluTessBeginPolygon*(tess: PGLUtesselator, polygon_data: Pointer){.
|
|
||||||
dynlib: dllname, importc: "gluTessBeginPolygon".}
|
|
||||||
proc gluTessBeginContour*(tess: PGLUtesselator){.dynlib: dllname,
|
|
||||||
importc: "gluTessBeginContour".}
|
|
||||||
proc gluTessVertex*(tess: PGLUtesselator, coords: var T3dArray, data: Pointer){.
|
|
||||||
dynlib: dllname, importc: "gluTessVertex".}
|
|
||||||
proc gluTessEndContour*(tess: PGLUtesselator){.dynlib: dllname,
|
|
||||||
importc: "gluTessEndContour".}
|
|
||||||
proc gluTessEndPolygon*(tess: PGLUtesselator){.dynlib: dllname,
|
|
||||||
importc: "gluTessEndPolygon".}
|
|
||||||
proc gluTessProperty*(tess: PGLUtesselator, which: TGLenum, value: TGLdouble){.
|
|
||||||
dynlib: dllname, importc: "gluTessProperty".}
|
|
||||||
proc gluTessNormal*(tess: PGLUtesselator, x, y, z: TGLdouble){.dynlib: dllname,
|
|
||||||
importc: "gluTessNormal".}
|
|
||||||
proc gluTessCallback*(tess: PGLUtesselator, which: TGLenum, fn: TCallBack){.
|
|
||||||
dynlib: dllname, importc: "gluTessCallback".}
|
|
||||||
proc gluGetTessProperty*(tess: PGLUtesselator, which: TGLenum, value: PGLdouble){.
|
|
||||||
dynlib: dllname, importc: "gluGetTessProperty".}
|
|
||||||
proc gluNewNurbsRenderer*(): PGLUnurbs{.dynlib: dllname,
|
|
||||||
importc: "gluNewNurbsRenderer".}
|
|
||||||
proc gluDeleteNurbsRenderer*(nobj: PGLUnurbs){.dynlib: dllname,
|
|
||||||
importc: "gluDeleteNurbsRenderer".}
|
|
||||||
proc gluBeginSurface*(nobj: PGLUnurbs){.dynlib: dllname,
|
|
||||||
importc: "gluBeginSurface".}
|
|
||||||
proc gluBeginCurve*(nobj: PGLUnurbs){.dynlib: dllname, importc: "gluBeginCurve".}
|
|
||||||
proc gluEndCurve*(nobj: PGLUnurbs){.dynlib: dllname, importc: "gluEndCurve".}
|
|
||||||
proc gluEndSurface*(nobj: PGLUnurbs){.dynlib: dllname, importc: "gluEndSurface".}
|
|
||||||
proc gluBeginTrim*(nobj: PGLUnurbs){.dynlib: dllname, importc: "gluBeginTrim".}
|
|
||||||
proc gluEndTrim*(nobj: PGLUnurbs){.dynlib: dllname, importc: "gluEndTrim".}
|
|
||||||
proc gluPwlCurve*(nobj: PGLUnurbs, count: TGLint, aarray: PGLfloat,
|
|
||||||
stride: TGLint, atype: TGLenum){.dynlib: dllname,
|
|
||||||
importc: "gluPwlCurve".}
|
|
||||||
proc gluNurbsCurve*(nobj: PGLUnurbs, nknots: TGLint, knot: PGLfloat,
|
|
||||||
stride: TGLint, ctlarray: PGLfloat, order: TGLint,
|
|
||||||
atype: TGLenum){.dynlib: dllname, importc: "gluNurbsCurve".}
|
|
||||||
proc gluNurbsSurface*(nobj: PGLUnurbs, sknot_count: TGLint, sknot: PGLfloat,
|
|
||||||
tknot_count: TGLint, tknot: PGLfloat,
|
|
||||||
s_stride, t_stride: TGLint, ctlarray: PGLfloat,
|
|
||||||
sorder, torder: TGLint, atype: TGLenum){.dynlib: dllname,
|
|
||||||
importc: "gluNurbsSurface".}
|
|
||||||
proc gluLoadSamplingMatrices*(nobj: PGLUnurbs,
|
|
||||||
modelMatrix, projMatrix: var T16dArray,
|
|
||||||
viewport: var TViewPortArray){.dynlib: dllname,
|
|
||||||
importc: "gluLoadSamplingMatrices".}
|
|
||||||
proc gluNurbsProperty*(nobj: PGLUnurbs, aproperty: TGLenum, value: TGLfloat){.
|
|
||||||
dynlib: dllname, importc: "gluNurbsProperty".}
|
|
||||||
proc gluGetNurbsProperty*(nobj: PGLUnurbs, aproperty: TGLenum, value: PGLfloat){.
|
|
||||||
dynlib: dllname, importc: "gluGetNurbsProperty".}
|
|
||||||
proc gluNurbsCallback*(nobj: PGLUnurbs, which: TGLenum, fn: TCallBack){.
|
|
||||||
dynlib: dllname, importc: "gluNurbsCallback".}
|
|
||||||
#*** Callback function prototypes ***
|
|
||||||
type # gluQuadricCallback
|
|
||||||
GLUquadricErrorProc* = proc (p: TGLenum) # gluTessCallback
|
|
||||||
GLUtessBeginProc* = proc (p: TGLenum)
|
|
||||||
GLUtessEdgeFlagProc* = proc (p: TGLboolean)
|
|
||||||
GLUtessVertexProc* = proc (p: Pointer)
|
|
||||||
GLUtessEndProc* = proc ()
|
|
||||||
GLUtessErrorProc* = proc (p: TGLenum)
|
|
||||||
GLUtessCombineProc* = proc (p1: var T3dArray, p2: T4pArray, p3: T4fArray,
|
|
||||||
p4: PPointer)
|
|
||||||
GLUtessBeginDataProc* = proc (p1: TGLenum, p2: Pointer)
|
|
||||||
GLUtessEdgeFlagDataProc* = proc (p1: TGLboolean, p2: Pointer)
|
|
||||||
GLUtessVertexDataProc* = proc (p1, p2: Pointer)
|
|
||||||
GLUtessEndDataProc* = proc (p: Pointer)
|
|
||||||
GLUtessErrorDataProc* = proc (p1: TGLenum, p2: Pointer)
|
|
||||||
GLUtessCombineDataProc* = proc (p1: var T3dArray, p2: var T4pArray,
|
|
||||||
p3: var T4fArray, p4: PPointer, p5: Pointer) #
|
|
||||||
#
|
|
||||||
# gluNurbsCallback
|
|
||||||
GLUnurbsErrorProc* = proc (p: TGLenum) #*** Generic constants ****/
|
|
||||||
|
|
||||||
const # Version
|
|
||||||
GLU_VERSION_1_1* = 1
|
|
||||||
GLU_VERSION_1_2* = 1 # Errors: (return value 0 = no error)
|
|
||||||
GLU_INVALID_ENUM* = 100900
|
|
||||||
GLU_INVALID_VALUE* = 100901
|
|
||||||
GLU_OUT_OF_MEMORY* = 100902
|
|
||||||
GLU_INCOMPATIBLE_GL_VERSION* = 100903 # StringName
|
|
||||||
GLU_VERSION* = 100800
|
|
||||||
GLU_EXTENSIONS* = 100801 # Boolean
|
|
||||||
GLU_TRUE* = GL_TRUE
|
|
||||||
GLU_FALSE* = GL_FALSE #*** Quadric constants ****/
|
|
||||||
# QuadricNormal
|
|
||||||
GLU_SMOOTH* = 100000
|
|
||||||
GLU_FLAT* = 100001
|
|
||||||
GLU_NONE* = 100002 # QuadricDrawStyle
|
|
||||||
GLU_POINT* = 100010
|
|
||||||
GLU_LINE* = 100011
|
|
||||||
GLU_FILL* = 100012
|
|
||||||
GLU_SILHOUETTE* = 100013 # QuadricOrientation
|
|
||||||
GLU_OUTSIDE* = 100020
|
|
||||||
GLU_INSIDE* = 100021 # Callback types:
|
|
||||||
# GLU_ERROR = 100103;
|
|
||||||
#*** Tesselation constants ****/
|
|
||||||
GLU_TESS_MAX_COORD* = 1.00000e+150 # TessProperty
|
|
||||||
GLU_TESS_WINDING_RULE* = 100140
|
|
||||||
GLU_TESS_BOUNDARY_ONLY* = 100141
|
|
||||||
GLU_TESS_TOLERANCE* = 100142 # TessWinding
|
|
||||||
GLU_TESS_WINDING_ODD* = 100130
|
|
||||||
GLU_TESS_WINDING_NONZERO* = 100131
|
|
||||||
GLU_TESS_WINDING_POSITIVE* = 100132
|
|
||||||
GLU_TESS_WINDING_NEGATIVE* = 100133
|
|
||||||
GLU_TESS_WINDING_ABS_GEQ_TWO* = 100134 # TessCallback
|
|
||||||
GLU_TESS_BEGIN* = 100100 # void (CALLBACK*)(TGLenum type)
|
|
||||||
constGLU_TESS_VERTEX* = 100101 # void (CALLBACK*)(void *data)
|
|
||||||
GLU_TESS_END* = 100102 # void (CALLBACK*)(void)
|
|
||||||
GLU_TESS_ERROR* = 100103 # void (CALLBACK*)(TGLenum errno)
|
|
||||||
GLU_TESS_EDGE_FLAG* = 100104 # void (CALLBACK*)(TGLboolean boundaryEdge)
|
|
||||||
GLU_TESS_COMBINE* = 100105 # void (CALLBACK*)(TGLdouble coords[3],
|
|
||||||
# void *data[4],
|
|
||||||
# TGLfloat weight[4],
|
|
||||||
# void **dataOut)
|
|
||||||
GLU_TESS_BEGIN_DATA* = 100106 # void (CALLBACK*)(TGLenum type,
|
|
||||||
# void *polygon_data)
|
|
||||||
GLU_TESS_VERTEX_DATA* = 100107 # void (CALLBACK*)(void *data,
|
|
||||||
# void *polygon_data)
|
|
||||||
GLU_TESS_END_DATA* = 100108 # void (CALLBACK*)(void *polygon_data)
|
|
||||||
GLU_TESS_ERROR_DATA* = 100109 # void (CALLBACK*)(TGLenum errno,
|
|
||||||
# void *polygon_data)
|
|
||||||
GLU_TESS_EDGE_FLAG_DATA* = 100110 # void (CALLBACK*)(TGLboolean boundaryEdge,
|
|
||||||
# void *polygon_data)
|
|
||||||
GLU_TESS_COMBINE_DATA* = 100111 # void (CALLBACK*)(TGLdouble coords[3],
|
|
||||||
# void *data[4],
|
|
||||||
# TGLfloat weight[4],
|
|
||||||
# void **dataOut,
|
|
||||||
# void *polygon_data)
|
|
||||||
# TessError
|
|
||||||
GLU_TESS_ERROR1* = 100151
|
|
||||||
GLU_TESS_ERROR2* = 100152
|
|
||||||
GLU_TESS_ERROR3* = 100153
|
|
||||||
GLU_TESS_ERROR4* = 100154
|
|
||||||
GLU_TESS_ERROR5* = 100155
|
|
||||||
GLU_TESS_ERROR6* = 100156
|
|
||||||
GLU_TESS_ERROR7* = 100157
|
|
||||||
GLU_TESS_ERROR8* = 100158
|
|
||||||
GLU_TESS_MISSING_BEGIN_POLYGON* = GLU_TESS_ERROR1
|
|
||||||
GLU_TESS_MISSING_BEGIN_CONTOUR* = GLU_TESS_ERROR2
|
|
||||||
GLU_TESS_MISSING_END_POLYGON* = GLU_TESS_ERROR3
|
|
||||||
GLU_TESS_MISSING_END_CONTOUR* = GLU_TESS_ERROR4
|
|
||||||
GLU_TESS_COORD_TOO_LARGE* = GLU_TESS_ERROR5
|
|
||||||
GLU_TESS_NEED_COMBINE_CALLBACK* = GLU_TESS_ERROR6 #*** NURBS constants ****/
|
|
||||||
# NurbsProperty
|
|
||||||
GLU_AUTO_LOAD_MATRIX* = 100200
|
|
||||||
GLU_CULLING* = 100201
|
|
||||||
GLU_SAMPLING_TOLERANCE* = 100203
|
|
||||||
GLU_DISPLAY_MODE* = 100204
|
|
||||||
GLU_PARAMETRIC_TOLERANCE* = 100202
|
|
||||||
GLU_SAMPLING_METHOD* = 100205
|
|
||||||
GLU_U_STEP* = 100206
|
|
||||||
GLU_V_STEP* = 100207 # NurbsSampling
|
|
||||||
GLU_PATH_LENGTH* = 100215
|
|
||||||
GLU_PARAMETRIC_ERROR* = 100216
|
|
||||||
GLU_DOMAIN_DISTANCE* = 100217 # NurbsTrim
|
|
||||||
GLU_MAP1_TRIM_2* = 100210
|
|
||||||
GLU_MAP1_TRIM_3* = 100211 # NurbsDisplay
|
|
||||||
# GLU_FILL = 100012;
|
|
||||||
GLU_OUTLINE_POLYGON* = 100240
|
|
||||||
GLU_OUTLINE_PATCH* = 100241 # NurbsCallback
|
|
||||||
# GLU_ERROR = 100103;
|
|
||||||
# NurbsErrors
|
|
||||||
GLU_NURBS_ERROR1* = 100251
|
|
||||||
GLU_NURBS_ERROR2* = 100252
|
|
||||||
GLU_NURBS_ERROR3* = 100253
|
|
||||||
GLU_NURBS_ERROR4* = 100254
|
|
||||||
GLU_NURBS_ERROR5* = 100255
|
|
||||||
GLU_NURBS_ERROR6* = 100256
|
|
||||||
GLU_NURBS_ERROR7* = 100257
|
|
||||||
GLU_NURBS_ERROR8* = 100258
|
|
||||||
GLU_NURBS_ERROR9* = 100259
|
|
||||||
GLU_NURBS_ERROR10* = 100260
|
|
||||||
GLU_NURBS_ERROR11* = 100261
|
|
||||||
GLU_NURBS_ERROR12* = 100262
|
|
||||||
GLU_NURBS_ERROR13* = 100263
|
|
||||||
GLU_NURBS_ERROR14* = 100264
|
|
||||||
GLU_NURBS_ERROR15* = 100265
|
|
||||||
GLU_NURBS_ERROR16* = 100266
|
|
||||||
GLU_NURBS_ERROR17* = 100267
|
|
||||||
GLU_NURBS_ERROR18* = 100268
|
|
||||||
GLU_NURBS_ERROR19* = 100269
|
|
||||||
GLU_NURBS_ERROR20* = 100270
|
|
||||||
GLU_NURBS_ERROR21* = 100271
|
|
||||||
GLU_NURBS_ERROR22* = 100272
|
|
||||||
GLU_NURBS_ERROR23* = 100273
|
|
||||||
GLU_NURBS_ERROR24* = 100274
|
|
||||||
GLU_NURBS_ERROR25* = 100275
|
|
||||||
GLU_NURBS_ERROR26* = 100276
|
|
||||||
GLU_NURBS_ERROR27* = 100277
|
|
||||||
GLU_NURBS_ERROR28* = 100278
|
|
||||||
GLU_NURBS_ERROR29* = 100279
|
|
||||||
GLU_NURBS_ERROR30* = 100280
|
|
||||||
GLU_NURBS_ERROR31* = 100281
|
|
||||||
GLU_NURBS_ERROR32* = 100282
|
|
||||||
GLU_NURBS_ERROR33* = 100283
|
|
||||||
GLU_NURBS_ERROR34* = 100284
|
|
||||||
GLU_NURBS_ERROR35* = 100285
|
|
||||||
GLU_NURBS_ERROR36* = 100286
|
|
||||||
GLU_NURBS_ERROR37* = 100287 #*** Backwards compatibility for old tesselator ****/
|
|
||||||
|
|
||||||
proc gluBeginPolygon*(tess: PGLUtesselator){.dynlib: dllname,
|
|
||||||
importc: "gluBeginPolygon".}
|
|
||||||
proc gluNextContour*(tess: PGLUtesselator, atype: TGLenum){.dynlib: dllname,
|
|
||||||
importc: "gluNextContour".}
|
|
||||||
proc gluEndPolygon*(tess: PGLUtesselator){.dynlib: dllname,
|
|
||||||
importc: "gluEndPolygon".}
|
|
||||||
const # Contours types -- obsolete!
|
|
||||||
GLU_CW* = 100120
|
|
||||||
GLU_CCW* = 100121
|
|
||||||
GLU_INTERIOR* = 100122
|
|
||||||
GLU_EXTERIOR* = 100123
|
|
||||||
GLU_UNKNOWN* = 100124 # Names without "TESS_" prefix
|
|
||||||
GLU_BEGIN* = GLU_TESS_BEGIN
|
|
||||||
GLU_VERTEX* = constGLU_TESS_VERTEX
|
|
||||||
GLU_END* = GLU_TESS_END
|
|
||||||
GLU_ERROR* = GLU_TESS_ERROR
|
|
||||||
GLU_EDGE_FLAG* = GLU_TESS_EDGE_FLAG
|
|
||||||
|
|
||||||
{.pop.}
|
|
||||||
# implementation
|
|
||||||
|
|
@ -1,438 +0,0 @@
|
||||||
#
|
|
||||||
#
|
|
||||||
# Adaption of the delphi3d.net OpenGL units to FreePascal
|
|
||||||
# Sebastian Guenther (sg@freepascal.org) in 2002
|
|
||||||
# These units are free to use
|
|
||||||
#
|
|
||||||
|
|
||||||
# Copyright (c) Mark J. Kilgard, 1994, 1995, 1996.
|
|
||||||
# This program is freely distributable without licensing fees and is
|
|
||||||
# provided without guarantee or warrantee expressed or implied. This
|
|
||||||
# program is -not- in the public domain.
|
|
||||||
#******************************************************************************
|
|
||||||
# Converted to Delphi by Tom Nuydens (tom@delphi3d.net)
|
|
||||||
# Contributions by Igor Karpov (glygrik@hotbox.ru)
|
|
||||||
# For the latest updates, visit Delphi3D: http://www.delphi3d.net
|
|
||||||
#******************************************************************************
|
|
||||||
|
|
||||||
import
|
|
||||||
GL
|
|
||||||
|
|
||||||
when defined(windows):
|
|
||||||
const
|
|
||||||
dllname = "glut32.dll"
|
|
||||||
elif defined(macosx):
|
|
||||||
const
|
|
||||||
dllname = "/System/Library/Frameworks/GLUT.framework/GLUT"
|
|
||||||
else:
|
|
||||||
const
|
|
||||||
dllname = "libglut.so.3"
|
|
||||||
type
|
|
||||||
TGlutVoidCallback* = proc (){.cdecl.}
|
|
||||||
TGlut1IntCallback* = proc (value: cint){.cdecl.}
|
|
||||||
TGlut2IntCallback* = proc (v1, v2: cint){.cdecl.}
|
|
||||||
TGlut3IntCallback* = proc (v1, v2, v3: cint){.cdecl.}
|
|
||||||
TGlut4IntCallback* = proc (v1, v2, v3, v4: cint){.cdecl.}
|
|
||||||
TGlut1Char2IntCallback* = proc (c: int8, v1, v2: cint){.cdecl.}
|
|
||||||
TGlut1UInt3IntCallback* = proc (u, v1, v2, v3: cint){.cdecl.}
|
|
||||||
|
|
||||||
const
|
|
||||||
GLUT_API_VERSION* = 3
|
|
||||||
GLUT_XLIB_IMPLEMENTATION* = 12 # Display mode bit masks.
|
|
||||||
GLUT_RGB* = 0
|
|
||||||
GLUT_RGBA* = GLUT_RGB
|
|
||||||
GLUT_INDEX* = 1
|
|
||||||
GLUT_SINGLE* = 0
|
|
||||||
GLUT_DOUBLE* = 2
|
|
||||||
GLUT_ACCUM* = 4
|
|
||||||
GLUT_ALPHA* = 8
|
|
||||||
GLUT_DEPTH* = 16
|
|
||||||
GLUT_STENCIL* = 32
|
|
||||||
GLUT_MULTISAMPLE* = 128
|
|
||||||
GLUT_STEREO* = 256
|
|
||||||
GLUT_LUMINANCE* = 512 # Mouse buttons.
|
|
||||||
GLUT_LEFT_BUTTON* = 0
|
|
||||||
GLUT_MIDDLE_BUTTON* = 1
|
|
||||||
GLUT_RIGHT_BUTTON* = 2 # Mouse button state.
|
|
||||||
GLUT_DOWN* = 0
|
|
||||||
GLUT_UP* = 1 # function keys
|
|
||||||
GLUT_KEY_F1* = 1
|
|
||||||
GLUT_KEY_F2* = 2
|
|
||||||
GLUT_KEY_F3* = 3
|
|
||||||
GLUT_KEY_F4* = 4
|
|
||||||
GLUT_KEY_F5* = 5
|
|
||||||
GLUT_KEY_F6* = 6
|
|
||||||
GLUT_KEY_F7* = 7
|
|
||||||
GLUT_KEY_F8* = 8
|
|
||||||
GLUT_KEY_F9* = 9
|
|
||||||
GLUT_KEY_F10* = 10
|
|
||||||
GLUT_KEY_F11* = 11
|
|
||||||
GLUT_KEY_F12* = 12 # directional keys
|
|
||||||
GLUT_KEY_LEFT* = 100
|
|
||||||
GLUT_KEY_UP* = 101
|
|
||||||
GLUT_KEY_RIGHT* = 102
|
|
||||||
GLUT_KEY_DOWN* = 103
|
|
||||||
GLUT_KEY_PAGE_UP* = 104
|
|
||||||
GLUT_KEY_PAGE_DOWN* = 105
|
|
||||||
GLUT_KEY_HOME* = 106
|
|
||||||
GLUT_KEY_END* = 107
|
|
||||||
GLUT_KEY_INSERT* = 108 # Entry/exit state.
|
|
||||||
GLUT_LEFT* = 0
|
|
||||||
GLUT_ENTERED* = 1 # Menu usage state.
|
|
||||||
GLUT_MENU_NOT_IN_USE* = 0
|
|
||||||
GLUT_MENU_IN_USE* = 1 # Visibility state.
|
|
||||||
GLUT_NOT_VISIBLE* = 0
|
|
||||||
GLUT_VISIBLE* = 1 # Window status state.
|
|
||||||
GLUT_HIDDEN* = 0
|
|
||||||
GLUT_FULLY_RETAINED* = 1
|
|
||||||
GLUT_PARTIALLY_RETAINED* = 2
|
|
||||||
GLUT_FULLY_COVERED* = 3 # Color index component selection values.
|
|
||||||
GLUT_RED* = 0
|
|
||||||
GLUT_GREEN* = 1
|
|
||||||
GLUT_BLUE* = 2 # Layers for use.
|
|
||||||
GLUT_NORMAL* = 0
|
|
||||||
GLUT_OVERLAY* = 1
|
|
||||||
|
|
||||||
when defined(Windows):
|
|
||||||
const # Stroke font constants (use these in GLUT program).
|
|
||||||
GLUT_STROKE_ROMAN* = cast[Pointer](0)
|
|
||||||
GLUT_STROKE_MONO_ROMAN* = cast[Pointer](1) # Bitmap font constants (use these in GLUT program).
|
|
||||||
GLUT_BITMAP_9_BY_15* = cast[Pointer](2)
|
|
||||||
GLUT_BITMAP_8_BY_13* = cast[Pointer](3)
|
|
||||||
GLUT_BITMAP_TIMES_ROMAN_10* = cast[Pointer](4)
|
|
||||||
GLUT_BITMAP_TIMES_ROMAN_24* = cast[Pointer](5)
|
|
||||||
GLUT_BITMAP_HELVETICA_10* = cast[Pointer](6)
|
|
||||||
GLUT_BITMAP_HELVETICA_12* = cast[Pointer](7)
|
|
||||||
GLUT_BITMAP_HELVETICA_18* = cast[Pointer](8)
|
|
||||||
else:
|
|
||||||
var # Stroke font constants (use these in GLUT program).
|
|
||||||
GLUT_STROKE_ROMAN*: Pointer
|
|
||||||
GLUT_STROKE_MONO_ROMAN*: Pointer # Bitmap font constants (use these in GLUT program).
|
|
||||||
GLUT_BITMAP_9_BY_15*: Pointer
|
|
||||||
GLUT_BITMAP_8_BY_13*: Pointer
|
|
||||||
GLUT_BITMAP_TIMES_ROMAN_10*: Pointer
|
|
||||||
GLUT_BITMAP_TIMES_ROMAN_24*: Pointer
|
|
||||||
GLUT_BITMAP_HELVETICA_10*: Pointer
|
|
||||||
GLUT_BITMAP_HELVETICA_12*: Pointer
|
|
||||||
GLUT_BITMAP_HELVETICA_18*: Pointer
|
|
||||||
const # glutGet parameters.
|
|
||||||
GLUT_WINDOW_X* = 100
|
|
||||||
GLUT_WINDOW_Y* = 101
|
|
||||||
GLUT_WINDOW_WIDTH* = 102
|
|
||||||
GLUT_WINDOW_HEIGHT* = 103
|
|
||||||
GLUT_WINDOW_BUFFER_SIZE* = 104
|
|
||||||
GLUT_WINDOW_STENCIL_SIZE* = 105
|
|
||||||
GLUT_WINDOW_DEPTH_SIZE* = 106
|
|
||||||
GLUT_WINDOW_RED_SIZE* = 107
|
|
||||||
GLUT_WINDOW_GREEN_SIZE* = 108
|
|
||||||
GLUT_WINDOW_BLUE_SIZE* = 109
|
|
||||||
GLUT_WINDOW_ALPHA_SIZE* = 110
|
|
||||||
GLUT_WINDOW_ACCUM_RED_SIZE* = 111
|
|
||||||
GLUT_WINDOW_ACCUM_GREEN_SIZE* = 112
|
|
||||||
GLUT_WINDOW_ACCUM_BLUE_SIZE* = 113
|
|
||||||
GLUT_WINDOW_ACCUM_ALPHA_SIZE* = 114
|
|
||||||
GLUT_WINDOW_DOUBLEBUFFER* = 115
|
|
||||||
GLUT_WINDOW_RGBA* = 116
|
|
||||||
GLUT_WINDOW_PARENT* = 117
|
|
||||||
GLUT_WINDOW_NUM_CHILDREN* = 118
|
|
||||||
GLUT_WINDOW_COLORMAP_SIZE* = 119
|
|
||||||
GLUT_WINDOW_NUM_SAMPLES* = 120
|
|
||||||
GLUT_WINDOW_STEREO* = 121
|
|
||||||
GLUT_WINDOW_CURSOR* = 122
|
|
||||||
GLUT_SCREEN_WIDTH* = 200
|
|
||||||
GLUT_SCREEN_HEIGHT* = 201
|
|
||||||
GLUT_SCREEN_WIDTH_MM* = 202
|
|
||||||
GLUT_SCREEN_HEIGHT_MM* = 203
|
|
||||||
GLUT_MENU_NUM_ITEMS* = 300
|
|
||||||
GLUT_DISPLAY_MODE_POSSIBLE* = 400
|
|
||||||
GLUT_INIT_WINDOW_X* = 500
|
|
||||||
GLUT_INIT_WINDOW_Y* = 501
|
|
||||||
GLUT_INIT_WINDOW_WIDTH* = 502
|
|
||||||
GLUT_INIT_WINDOW_HEIGHT* = 503
|
|
||||||
constGLUT_INIT_DISPLAY_MODE* = 504
|
|
||||||
GLUT_ELAPSED_TIME* = 700
|
|
||||||
GLUT_WINDOW_FORMAT_ID* = 123 # glutDeviceGet parameters.
|
|
||||||
GLUT_HAS_KEYBOARD* = 600
|
|
||||||
GLUT_HAS_MOUSE* = 601
|
|
||||||
GLUT_HAS_SPACEBALL* = 602
|
|
||||||
GLUT_HAS_DIAL_AND_BUTTON_BOX* = 603
|
|
||||||
GLUT_HAS_TABLET* = 604
|
|
||||||
GLUT_NUM_MOUSE_BUTTONS* = 605
|
|
||||||
GLUT_NUM_SPACEBALL_BUTTONS* = 606
|
|
||||||
GLUT_NUM_BUTTON_BOX_BUTTONS* = 607
|
|
||||||
GLUT_NUM_DIALS* = 608
|
|
||||||
GLUT_NUM_TABLET_BUTTONS* = 609
|
|
||||||
GLUT_DEVICE_IGNORE_KEY_REPEAT* = 610
|
|
||||||
GLUT_DEVICE_KEY_REPEAT* = 611
|
|
||||||
GLUT_HAS_JOYSTICK* = 612
|
|
||||||
GLUT_OWNS_JOYSTICK* = 613
|
|
||||||
GLUT_JOYSTICK_BUTTONS* = 614
|
|
||||||
GLUT_JOYSTICK_AXES* = 615
|
|
||||||
GLUT_JOYSTICK_POLL_RATE* = 616 # glutLayerGet parameters.
|
|
||||||
GLUT_OVERLAY_POSSIBLE* = 800
|
|
||||||
GLUT_LAYER_IN_USE* = 801
|
|
||||||
GLUT_HAS_OVERLAY* = 802
|
|
||||||
GLUT_TRANSPARENT_INDEX* = 803
|
|
||||||
GLUT_NORMAL_DAMAGED* = 804
|
|
||||||
GLUT_OVERLAY_DAMAGED* = 805 # glutVideoResizeGet parameters.
|
|
||||||
GLUT_VIDEO_RESIZE_POSSIBLE* = 900
|
|
||||||
GLUT_VIDEO_RESIZE_IN_USE* = 901
|
|
||||||
GLUT_VIDEO_RESIZE_X_DELTA* = 902
|
|
||||||
GLUT_VIDEO_RESIZE_Y_DELTA* = 903
|
|
||||||
GLUT_VIDEO_RESIZE_WIDTH_DELTA* = 904
|
|
||||||
GLUT_VIDEO_RESIZE_HEIGHT_DELTA* = 905
|
|
||||||
GLUT_VIDEO_RESIZE_X* = 906
|
|
||||||
GLUT_VIDEO_RESIZE_Y* = 907
|
|
||||||
GLUT_VIDEO_RESIZE_WIDTH* = 908
|
|
||||||
GLUT_VIDEO_RESIZE_HEIGHT* = 909 # glutGetModifiers return mask.
|
|
||||||
GLUT_ACTIVE_SHIFT* = 1
|
|
||||||
GLUT_ACTIVE_CTRL* = 2
|
|
||||||
GLUT_ACTIVE_ALT* = 4 # glutSetCursor parameters.
|
|
||||||
# Basic arrows.
|
|
||||||
GLUT_CURSOR_RIGHT_ARROW* = 0
|
|
||||||
GLUT_CURSOR_LEFT_ARROW* = 1 # Symbolic cursor shapes.
|
|
||||||
GLUT_CURSOR_INFO* = 2
|
|
||||||
GLUT_CURSOR_DESTROY* = 3
|
|
||||||
GLUT_CURSOR_HELP* = 4
|
|
||||||
GLUT_CURSOR_CYCLE* = 5
|
|
||||||
GLUT_CURSOR_SPRAY* = 6
|
|
||||||
GLUT_CURSOR_WAIT* = 7
|
|
||||||
GLUT_CURSOR_TEXT* = 8
|
|
||||||
GLUT_CURSOR_CROSSHAIR* = 9 # Directional cursors.
|
|
||||||
GLUT_CURSOR_UP_DOWN* = 10
|
|
||||||
GLUT_CURSOR_LEFT_RIGHT* = 11 # Sizing cursors.
|
|
||||||
GLUT_CURSOR_TOP_SIDE* = 12
|
|
||||||
GLUT_CURSOR_BOTTOM_SIDE* = 13
|
|
||||||
GLUT_CURSOR_LEFT_SIDE* = 14
|
|
||||||
GLUT_CURSOR_RIGHT_SIDE* = 15
|
|
||||||
GLUT_CURSOR_TOP_LEFT_CORNER* = 16
|
|
||||||
GLUT_CURSOR_TOP_RIGHT_CORNER* = 17
|
|
||||||
GLUT_CURSOR_BOTTOM_RIGHT_CORNER* = 18
|
|
||||||
GLUT_CURSOR_BOTTOM_LEFT_CORNER* = 19 # Inherit from parent window.
|
|
||||||
GLUT_CURSOR_INHERIT* = 100 # Blank cursor.
|
|
||||||
GLUT_CURSOR_NONE* = 101 # Fullscreen crosshair (if available).
|
|
||||||
GLUT_CURSOR_FULL_CROSSHAIR* = 102 # GLUT device control sub-API.
|
|
||||||
# glutSetKeyRepeat modes.
|
|
||||||
GLUT_KEY_REPEAT_OFF* = 0
|
|
||||||
GLUT_KEY_REPEAT_ON* = 1
|
|
||||||
GLUT_KEY_REPEAT_DEFAULT* = 2 # Joystick button masks.
|
|
||||||
GLUT_JOYSTICK_BUTTON_A* = 1
|
|
||||||
GLUT_JOYSTICK_BUTTON_B* = 2
|
|
||||||
GLUT_JOYSTICK_BUTTON_C* = 4
|
|
||||||
GLUT_JOYSTICK_BUTTON_D* = 8 # GLUT game mode sub-API.
|
|
||||||
# glutGameModeGet.
|
|
||||||
GLUT_GAME_MODE_ACTIVE* = 0
|
|
||||||
GLUT_GAME_MODE_POSSIBLE* = 1
|
|
||||||
GLUT_GAME_MODE_WIDTH* = 2
|
|
||||||
GLUT_GAME_MODE_HEIGHT* = 3
|
|
||||||
GLUT_GAME_MODE_PIXEL_DEPTH* = 4
|
|
||||||
GLUT_GAME_MODE_REFRESH_RATE* = 5
|
|
||||||
GLUT_GAME_MODE_DISPLAY_CHANGED* = 6 # GLUT initialization sub-API.
|
|
||||||
|
|
||||||
proc glutInit*(argcp: ptr cint, argv: pointer){.dynlib: dllname,
|
|
||||||
importc: "glutInit".}
|
|
||||||
|
|
||||||
proc glutInit*() =
|
|
||||||
## version that passes `argc` and `argc` implicitely.
|
|
||||||
var
|
|
||||||
cmdLine {.importc: "cmdLine".}: array[0..255, cstring]
|
|
||||||
cmdCount {.importc: "cmdCount".}: cint
|
|
||||||
glutInit(addr(cmdCount), addr(cmdLine))
|
|
||||||
|
|
||||||
proc glutInitDisplayMode*(mode: int16){.dynlib: dllname,
|
|
||||||
importc: "glutInitDisplayMode".}
|
|
||||||
proc glutInitDisplayString*(str: cstring){.dynlib: dllname,
|
|
||||||
importc: "glutInitDisplayString".}
|
|
||||||
proc glutInitWindowPosition*(x, y: int){.dynlib: dllname,
|
|
||||||
importc: "glutInitWindowPosition".}
|
|
||||||
proc glutInitWindowSize*(width, height: int){.dynlib: dllname,
|
|
||||||
importc: "glutInitWindowSize".}
|
|
||||||
proc glutMainLoop*(){.dynlib: dllname, importc: "glutMainLoop".}
|
|
||||||
# GLUT window sub-API.
|
|
||||||
proc glutCreateWindow*(title: cstring): int{.dynlib: dllname,
|
|
||||||
importc: "glutCreateWindow".}
|
|
||||||
proc glutCreateSubWindow*(win, x, y, width, height: int): int{.dynlib: dllname,
|
|
||||||
importc: "glutCreateSubWindow".}
|
|
||||||
proc glutDestroyWindow*(win: int){.dynlib: dllname, importc: "glutDestroyWindow".}
|
|
||||||
proc glutPostRedisplay*(){.dynlib: dllname, importc: "glutPostRedisplay".}
|
|
||||||
proc glutPostWindowRedisplay*(win: int){.dynlib: dllname,
|
|
||||||
importc: "glutPostWindowRedisplay".}
|
|
||||||
proc glutSwapBuffers*(){.dynlib: dllname, importc: "glutSwapBuffers".}
|
|
||||||
proc glutGetWindow*(): int{.dynlib: dllname, importc: "glutGetWindow".}
|
|
||||||
proc glutSetWindow*(win: int){.dynlib: dllname, importc: "glutSetWindow".}
|
|
||||||
proc glutSetWindowTitle*(title: cstring){.dynlib: dllname,
|
|
||||||
importc: "glutSetWindowTitle".}
|
|
||||||
proc glutSetIconTitle*(title: cstring){.dynlib: dllname,
|
|
||||||
importc: "glutSetIconTitle".}
|
|
||||||
proc glutPositionWindow*(x, y: int){.dynlib: dllname,
|
|
||||||
importc: "glutPositionWindow".}
|
|
||||||
proc glutReshapeWindow*(width, height: int){.dynlib: dllname,
|
|
||||||
importc: "glutReshapeWindow".}
|
|
||||||
proc glutPopWindow*(){.dynlib: dllname, importc: "glutPopWindow".}
|
|
||||||
proc glutPushWindow*(){.dynlib: dllname, importc: "glutPushWindow".}
|
|
||||||
proc glutIconifyWindow*(){.dynlib: dllname, importc: "glutIconifyWindow".}
|
|
||||||
proc glutShowWindow*(){.dynlib: dllname, importc: "glutShowWindow".}
|
|
||||||
proc glutHideWindow*(){.dynlib: dllname, importc: "glutHideWindow".}
|
|
||||||
proc glutFullScreen*(){.dynlib: dllname, importc: "glutFullScreen".}
|
|
||||||
proc glutSetCursor*(cursor: int){.dynlib: dllname, importc: "glutSetCursor".}
|
|
||||||
proc glutWarpPointer*(x, y: int){.dynlib: dllname, importc: "glutWarpPointer".}
|
|
||||||
# GLUT overlay sub-API.
|
|
||||||
proc glutEstablishOverlay*(){.dynlib: dllname, importc: "glutEstablishOverlay".}
|
|
||||||
proc glutRemoveOverlay*(){.dynlib: dllname, importc: "glutRemoveOverlay".}
|
|
||||||
proc glutUseLayer*(layer: TGLenum){.dynlib: dllname, importc: "glutUseLayer".}
|
|
||||||
proc glutPostOverlayRedisplay*(){.dynlib: dllname,
|
|
||||||
importc: "glutPostOverlayRedisplay".}
|
|
||||||
proc glutPostWindowOverlayRedisplay*(win: int){.dynlib: dllname,
|
|
||||||
importc: "glutPostWindowOverlayRedisplay".}
|
|
||||||
proc glutShowOverlay*(){.dynlib: dllname, importc: "glutShowOverlay".}
|
|
||||||
proc glutHideOverlay*(){.dynlib: dllname, importc: "glutHideOverlay".}
|
|
||||||
# GLUT menu sub-API.
|
|
||||||
proc glutCreateMenu*(callback: TGlut1IntCallback): int{.dynlib: dllname,
|
|
||||||
importc: "glutCreateMenu".}
|
|
||||||
proc glutDestroyMenu*(menu: int){.dynlib: dllname, importc: "glutDestroyMenu".}
|
|
||||||
proc glutGetMenu*(): int{.dynlib: dllname, importc: "glutGetMenu".}
|
|
||||||
proc glutSetMenu*(menu: int){.dynlib: dllname, importc: "glutSetMenu".}
|
|
||||||
proc glutAddMenuEntry*(caption: cstring, value: int){.dynlib: dllname,
|
|
||||||
importc: "glutAddMenuEntry".}
|
|
||||||
proc glutAddSubMenu*(caption: cstring, submenu: int){.dynlib: dllname,
|
|
||||||
importc: "glutAddSubMenu".}
|
|
||||||
proc glutChangeToMenuEntry*(item: int, caption: cstring, value: int){.
|
|
||||||
dynlib: dllname, importc: "glutChangeToMenuEntry".}
|
|
||||||
proc glutChangeToSubMenu*(item: int, caption: cstring, submenu: int){.
|
|
||||||
dynlib: dllname, importc: "glutChangeToSubMenu".}
|
|
||||||
proc glutRemoveMenuItem*(item: int){.dynlib: dllname,
|
|
||||||
importc: "glutRemoveMenuItem".}
|
|
||||||
proc glutAttachMenu*(button: int){.dynlib: dllname, importc: "glutAttachMenu".}
|
|
||||||
proc glutDetachMenu*(button: int){.dynlib: dllname, importc: "glutDetachMenu".}
|
|
||||||
# GLUT window callback sub-API.
|
|
||||||
proc glutDisplayFunc*(f: TGlutVoidCallback){.dynlib: dllname,
|
|
||||||
importc: "glutDisplayFunc".}
|
|
||||||
proc glutReshapeFunc*(f: TGlut2IntCallback){.dynlib: dllname,
|
|
||||||
importc: "glutReshapeFunc".}
|
|
||||||
proc glutKeyboardFunc*(f: TGlut1Char2IntCallback){.dynlib: dllname,
|
|
||||||
importc: "glutKeyboardFunc".}
|
|
||||||
proc glutMouseFunc*(f: TGlut4IntCallback){.dynlib: dllname,
|
|
||||||
importc: "glutMouseFunc".}
|
|
||||||
proc glutMotionFunc*(f: TGlut2IntCallback){.dynlib: dllname,
|
|
||||||
importc: "glutMotionFunc".}
|
|
||||||
proc glutPassiveMotionFunc*(f: TGlut2IntCallback){.dynlib: dllname,
|
|
||||||
importc: "glutPassiveMotionFunc".}
|
|
||||||
proc glutEntryFunc*(f: TGlut1IntCallback){.dynlib: dllname,
|
|
||||||
importc: "glutEntryFunc".}
|
|
||||||
proc glutVisibilityFunc*(f: TGlut1IntCallback){.dynlib: dllname,
|
|
||||||
importc: "glutVisibilityFunc".}
|
|
||||||
proc glutIdleFunc*(f: TGlutVoidCallback){.dynlib: dllname,
|
|
||||||
importc: "glutIdleFunc".}
|
|
||||||
proc glutTimerFunc*(millis: int16, f: TGlut1IntCallback, value: int){.
|
|
||||||
dynlib: dllname, importc: "glutTimerFunc".}
|
|
||||||
proc glutMenuStateFunc*(f: TGlut1IntCallback){.dynlib: dllname,
|
|
||||||
importc: "glutMenuStateFunc".}
|
|
||||||
proc glutSpecialFunc*(f: TGlut3IntCallback){.dynlib: dllname,
|
|
||||||
importc: "glutSpecialFunc".}
|
|
||||||
proc glutSpaceballMotionFunc*(f: TGlut3IntCallback){.dynlib: dllname,
|
|
||||||
importc: "glutSpaceballMotionFunc".}
|
|
||||||
proc glutSpaceballRotateFunc*(f: TGlut3IntCallback){.dynlib: dllname,
|
|
||||||
importc: "glutSpaceballRotateFunc".}
|
|
||||||
proc glutSpaceballButtonFunc*(f: TGlut2IntCallback){.dynlib: dllname,
|
|
||||||
importc: "glutSpaceballButtonFunc".}
|
|
||||||
proc glutButtonBoxFunc*(f: TGlut2IntCallback){.dynlib: dllname,
|
|
||||||
importc: "glutButtonBoxFunc".}
|
|
||||||
proc glutDialsFunc*(f: TGlut2IntCallback){.dynlib: dllname,
|
|
||||||
importc: "glutDialsFunc".}
|
|
||||||
proc glutTabletMotionFunc*(f: TGlut2IntCallback){.dynlib: dllname,
|
|
||||||
importc: "glutTabletMotionFunc".}
|
|
||||||
proc glutTabletButtonFunc*(f: TGlut4IntCallback){.dynlib: dllname,
|
|
||||||
importc: "glutTabletButtonFunc".}
|
|
||||||
proc glutMenuStatusFunc*(f: TGlut3IntCallback){.dynlib: dllname,
|
|
||||||
importc: "glutMenuStatusFunc".}
|
|
||||||
proc glutOverlayDisplayFunc*(f: TGlutVoidCallback){.dynlib: dllname,
|
|
||||||
importc: "glutOverlayDisplayFunc".}
|
|
||||||
proc glutWindowStatusFunc*(f: TGlut1IntCallback){.dynlib: dllname,
|
|
||||||
importc: "glutWindowStatusFunc".}
|
|
||||||
proc glutKeyboardUpFunc*(f: TGlut1Char2IntCallback){.dynlib: dllname,
|
|
||||||
importc: "glutKeyboardUpFunc".}
|
|
||||||
proc glutSpecialUpFunc*(f: TGlut3IntCallback){.dynlib: dllname,
|
|
||||||
importc: "glutSpecialUpFunc".}
|
|
||||||
proc glutJoystickFunc*(f: TGlut1UInt3IntCallback, pollInterval: int){.
|
|
||||||
dynlib: dllname, importc: "glutJoystickFunc".}
|
|
||||||
# GLUT color index sub-API.
|
|
||||||
proc glutSetColor*(cell: int, red, green, blue: TGLfloat){.dynlib: dllname,
|
|
||||||
importc: "glutSetColor".}
|
|
||||||
proc glutGetColor*(ndx, component: int): TGLfloat{.dynlib: dllname,
|
|
||||||
importc: "glutGetColor".}
|
|
||||||
proc glutCopyColormap*(win: int){.dynlib: dllname, importc: "glutCopyColormap".}
|
|
||||||
# GLUT state retrieval sub-API.
|
|
||||||
proc glutGet*(t: TGLenum): int{.dynlib: dllname, importc: "glutGet".}
|
|
||||||
proc glutDeviceGet*(t: TGLenum): int{.dynlib: dllname, importc: "glutDeviceGet".}
|
|
||||||
# GLUT extension support sub-API
|
|
||||||
proc glutExtensionSupported*(name: cstring): int{.dynlib: dllname,
|
|
||||||
importc: "glutExtensionSupported".}
|
|
||||||
proc glutGetModifiers*(): int{.dynlib: dllname, importc: "glutGetModifiers".}
|
|
||||||
proc glutLayerGet*(t: TGLenum): int{.dynlib: dllname, importc: "glutLayerGet".}
|
|
||||||
# GLUT font sub-API
|
|
||||||
proc glutBitmapCharacter*(font: pointer, character: int){.dynlib: dllname,
|
|
||||||
importc: "glutBitmapCharacter".}
|
|
||||||
proc glutBitmapWidth*(font: pointer, character: int): int{.dynlib: dllname,
|
|
||||||
importc: "glutBitmapWidth".}
|
|
||||||
proc glutStrokeCharacter*(font: pointer, character: int){.dynlib: dllname,
|
|
||||||
importc: "glutStrokeCharacter".}
|
|
||||||
proc glutStrokeWidth*(font: pointer, character: int): int{.dynlib: dllname,
|
|
||||||
importc: "glutStrokeWidth".}
|
|
||||||
proc glutBitmapLength*(font: pointer, str: cstring): int{.dynlib: dllname,
|
|
||||||
importc: "glutBitmapLength".}
|
|
||||||
proc glutStrokeLength*(font: pointer, str: cstring): int{.dynlib: dllname,
|
|
||||||
importc: "glutStrokeLength".}
|
|
||||||
# GLUT pre-built models sub-API
|
|
||||||
proc glutWireSphere*(radius: TGLdouble, slices, stacks: TGLint){.
|
|
||||||
dynlib: dllname, importc: "glutWireSphere".}
|
|
||||||
proc glutSolidSphere*(radius: TGLdouble, slices, stacks: TGLint){.
|
|
||||||
dynlib: dllname, importc: "glutSolidSphere".}
|
|
||||||
proc glutWireCone*(base, height: TGLdouble, slices, stacks: TGLint){.
|
|
||||||
dynlib: dllname, importc: "glutWireCone".}
|
|
||||||
proc glutSolidCone*(base, height: TGLdouble, slices, stacks: TGLint){.
|
|
||||||
dynlib: dllname, importc: "glutSolidCone".}
|
|
||||||
proc glutWireCube*(size: TGLdouble){.dynlib: dllname, importc: "glutWireCube".}
|
|
||||||
proc glutSolidCube*(size: TGLdouble){.dynlib: dllname, importc: "glutSolidCube".}
|
|
||||||
proc glutWireTorus*(innerRadius, outerRadius: TGLdouble, sides, rings: TGLint){.
|
|
||||||
dynlib: dllname, importc: "glutWireTorus".}
|
|
||||||
proc glutSolidTorus*(innerRadius, outerRadius: TGLdouble, sides, rings: TGLint){.
|
|
||||||
dynlib: dllname, importc: "glutSolidTorus".}
|
|
||||||
proc glutWireDodecahedron*(){.dynlib: dllname, importc: "glutWireDodecahedron".}
|
|
||||||
proc glutSolidDodecahedron*(){.dynlib: dllname, importc: "glutSolidDodecahedron".}
|
|
||||||
proc glutWireTeapot*(size: TGLdouble){.dynlib: dllname,
|
|
||||||
importc: "glutWireTeapot".}
|
|
||||||
proc glutSolidTeapot*(size: TGLdouble){.dynlib: dllname,
|
|
||||||
importc: "glutSolidTeapot".}
|
|
||||||
proc glutWireOctahedron*(){.dynlib: dllname, importc: "glutWireOctahedron".}
|
|
||||||
proc glutSolidOctahedron*(){.dynlib: dllname, importc: "glutSolidOctahedron".}
|
|
||||||
proc glutWireTetrahedron*(){.dynlib: dllname, importc: "glutWireTetrahedron".}
|
|
||||||
proc glutSolidTetrahedron*(){.dynlib: dllname, importc: "glutSolidTetrahedron".}
|
|
||||||
proc glutWireIcosahedron*(){.dynlib: dllname, importc: "glutWireIcosahedron".}
|
|
||||||
proc glutSolidIcosahedron*(){.dynlib: dllname, importc: "glutSolidIcosahedron".}
|
|
||||||
# GLUT video resize sub-API.
|
|
||||||
proc glutVideoResizeGet*(param: TGLenum): int{.dynlib: dllname,
|
|
||||||
importc: "glutVideoResizeGet".}
|
|
||||||
proc glutSetupVideoResizing*(){.dynlib: dllname,
|
|
||||||
importc: "glutSetupVideoResizing".}
|
|
||||||
proc glutStopVideoResizing*(){.dynlib: dllname, importc: "glutStopVideoResizing".}
|
|
||||||
proc glutVideoResize*(x, y, width, height: int){.dynlib: dllname,
|
|
||||||
importc: "glutVideoResize".}
|
|
||||||
proc glutVideoPan*(x, y, width, height: int){.dynlib: dllname,
|
|
||||||
importc: "glutVideoPan".}
|
|
||||||
# GLUT debugging sub-API.
|
|
||||||
proc glutReportErrors*(){.dynlib: dllname, importc: "glutReportErrors".}
|
|
||||||
# GLUT device control sub-API.
|
|
||||||
proc glutIgnoreKeyRepeat*(ignore: int){.dynlib: dllname,
|
|
||||||
importc: "glutIgnoreKeyRepeat".}
|
|
||||||
proc glutSetKeyRepeat*(repeatMode: int){.dynlib: dllname,
|
|
||||||
importc: "glutSetKeyRepeat".}
|
|
||||||
proc glutForceJoystickFunc*(){.dynlib: dllname, importc: "glutForceJoystickFunc".}
|
|
||||||
# GLUT game mode sub-API.
|
|
||||||
#example glutGameModeString('1280x1024:32@75');
|
|
||||||
proc glutGameModeString*(AString: cstring){.dynlib: dllname,
|
|
||||||
importc: "glutGameModeString".}
|
|
||||||
proc glutEnterGameMode*(): int{.dynlib: dllname, importc: "glutEnterGameMode".}
|
|
||||||
proc glutLeaveGameMode*(){.dynlib: dllname, importc: "glutLeaveGameMode".}
|
|
||||||
proc glutGameModeGet*(mode: TGLenum): int{.dynlib: dllname,
|
|
||||||
importc: "glutGameModeGet".}
|
|
||||||
# implementation
|
|
||||||
|
|
@ -1,153 +0,0 @@
|
||||||
#
|
|
||||||
#
|
|
||||||
# Translation of the Mesa GLX headers for FreePascal
|
|
||||||
# Copyright (C) 1999 Sebastian Guenther
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# Mesa 3-D graphics library
|
|
||||||
# Version: 3.0
|
|
||||||
# Copyright (C) 1995-1998 Brian Paul
|
|
||||||
#
|
|
||||||
# This library is free software; you can redistribute it and/or
|
|
||||||
# modify it under the terms of the GNU Library General Public
|
|
||||||
# License as published by the Free Software Foundation; either
|
|
||||||
# version 2 of the License, or (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This library is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
# Library General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Library General Public
|
|
||||||
# License along with this library; if not, write to the Free
|
|
||||||
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
||||||
#
|
|
||||||
|
|
||||||
import
|
|
||||||
X, XLib, XUtil, gl
|
|
||||||
|
|
||||||
when defined(windows):
|
|
||||||
const
|
|
||||||
dllname = "GL.dll"
|
|
||||||
elif defined(macosx):
|
|
||||||
const
|
|
||||||
dllname = "/usr/X11R6/lib/libGL.dylib"
|
|
||||||
else:
|
|
||||||
const
|
|
||||||
dllname = "libGL.so"
|
|
||||||
const
|
|
||||||
GLX_USE_GL* = 1
|
|
||||||
GLX_BUFFER_SIZE* = 2
|
|
||||||
GLX_LEVEL* = 3
|
|
||||||
GLX_RGBA* = 4
|
|
||||||
GLX_DOUBLEBUFFER* = 5
|
|
||||||
GLX_STEREO* = 6
|
|
||||||
GLX_AUX_BUFFERS* = 7
|
|
||||||
GLX_RED_SIZE* = 8
|
|
||||||
GLX_GREEN_SIZE* = 9
|
|
||||||
GLX_BLUE_SIZE* = 10
|
|
||||||
GLX_ALPHA_SIZE* = 11
|
|
||||||
GLX_DEPTH_SIZE* = 12
|
|
||||||
GLX_STENCIL_SIZE* = 13
|
|
||||||
GLX_ACCUM_RED_SIZE* = 14
|
|
||||||
GLX_ACCUM_GREEN_SIZE* = 15
|
|
||||||
GLX_ACCUM_BLUE_SIZE* = 16
|
|
||||||
GLX_ACCUM_ALPHA_SIZE* = 17 # GLX_EXT_visual_info extension
|
|
||||||
GLX_X_VISUAL_TYPE_EXT* = 0x00000022
|
|
||||||
GLX_TRANSPARENT_TYPE_EXT* = 0x00000023
|
|
||||||
GLX_TRANSPARENT_INDEX_VALUE_EXT* = 0x00000024
|
|
||||||
GLX_TRANSPARENT_RED_VALUE_EXT* = 0x00000025
|
|
||||||
GLX_TRANSPARENT_GREEN_VALUE_EXT* = 0x00000026
|
|
||||||
GLX_TRANSPARENT_BLUE_VALUE_EXT* = 0x00000027
|
|
||||||
GLX_TRANSPARENT_ALPHA_VALUE_EXT* = 0x00000028 # Error codes returned by glXGetConfig:
|
|
||||||
GLX_BAD_SCREEN* = 1
|
|
||||||
GLX_BAD_ATTRIBUTE* = 2
|
|
||||||
GLX_NO_EXTENSION* = 3
|
|
||||||
GLX_BAD_VISUAL* = 4
|
|
||||||
GLX_BAD_CONTEXT* = 5
|
|
||||||
GLX_BAD_VALUE* = 6
|
|
||||||
GLX_BAD_ENUM* = 7 # GLX 1.1 and later:
|
|
||||||
GLX_VENDOR* = 1
|
|
||||||
GLX_VERSION* = 2
|
|
||||||
GLX_EXTENSIONS* = 3 # GLX_visual_info extension
|
|
||||||
GLX_TRUE_COLOR_EXT* = 0x00008002
|
|
||||||
GLX_DIRECT_COLOR_EXT* = 0x00008003
|
|
||||||
GLX_PSEUDO_COLOR_EXT* = 0x00008004
|
|
||||||
GLX_STATIC_COLOR_EXT* = 0x00008005
|
|
||||||
GLX_GRAY_SCALE_EXT* = 0x00008006
|
|
||||||
GLX_STATIC_GRAY_EXT* = 0x00008007
|
|
||||||
GLX_NONE_EXT* = 0x00008000
|
|
||||||
GLX_TRANSPARENT_RGB_EXT* = 0x00008008
|
|
||||||
GLX_TRANSPARENT_INDEX_EXT* = 0x00008009
|
|
||||||
|
|
||||||
type # From XLib:
|
|
||||||
XPixmap* = TXID
|
|
||||||
XFont* = TXID
|
|
||||||
XColormap* = TXID
|
|
||||||
GLXContext* = Pointer
|
|
||||||
GLXPixmap* = TXID
|
|
||||||
GLXDrawable* = TXID
|
|
||||||
GLXContextID* = TXID
|
|
||||||
TXPixmap* = XPixmap
|
|
||||||
TXFont* = XFont
|
|
||||||
TXColormap* = XColormap
|
|
||||||
TGLXContext* = GLXContext
|
|
||||||
TGLXPixmap* = GLXPixmap
|
|
||||||
TGLXDrawable* = GLXDrawable
|
|
||||||
TGLXContextID* = GLXContextID
|
|
||||||
|
|
||||||
proc glXChooseVisual*(dpy: PDisplay, screen: int, attribList: ptr int32): PXVisualInfo{.
|
|
||||||
cdecl, dynlib: dllname, importc: "glXChooseVisual".}
|
|
||||||
proc glXCreateContext*(dpy: PDisplay, vis: PXVisualInfo, shareList: GLXContext,
|
|
||||||
direct: bool): GLXContext{.cdecl, dynlib: dllname,
|
|
||||||
importc: "glXCreateContext".}
|
|
||||||
proc glXDestroyContext*(dpy: PDisplay, ctx: GLXContext){.cdecl, dynlib: dllname,
|
|
||||||
importc: "glXDestroyContext".}
|
|
||||||
proc glXMakeCurrent*(dpy: PDisplay, drawable: GLXDrawable, ctx: GLXContext): bool{.
|
|
||||||
cdecl, dynlib: dllname, importc: "glXMakeCurrent".}
|
|
||||||
proc glXCopyContext*(dpy: PDisplay, src, dst: GLXContext, mask: int32){.cdecl,
|
|
||||||
dynlib: dllname, importc: "glXCopyContext".}
|
|
||||||
proc glXSwapBuffers*(dpy: PDisplay, drawable: GLXDrawable){.cdecl,
|
|
||||||
dynlib: dllname, importc: "glXSwapBuffers".}
|
|
||||||
proc glXCreateGLXPixmap*(dpy: PDisplay, visual: PXVisualInfo, pixmap: XPixmap): GLXPixmap{.
|
|
||||||
cdecl, dynlib: dllname, importc: "glXCreateGLXPixmap".}
|
|
||||||
proc glXDestroyGLXPixmap*(dpy: PDisplay, pixmap: GLXPixmap){.cdecl,
|
|
||||||
dynlib: dllname, importc: "glXDestroyGLXPixmap".}
|
|
||||||
proc glXQueryExtension*(dpy: PDisplay, errorb, event: var int): bool{.cdecl,
|
|
||||||
dynlib: dllname, importc: "glXQueryExtension".}
|
|
||||||
proc glXQueryVersion*(dpy: PDisplay, maj, min: var int): bool{.cdecl,
|
|
||||||
dynlib: dllname, importc: "glXQueryVersion".}
|
|
||||||
proc glXIsDirect*(dpy: PDisplay, ctx: GLXContext): bool{.cdecl, dynlib: dllname,
|
|
||||||
importc: "glXIsDirect".}
|
|
||||||
proc glXGetConfig*(dpy: PDisplay, visual: PXVisualInfo, attrib: int,
|
|
||||||
value: var int): int{.cdecl, dynlib: dllname,
|
|
||||||
importc: "glXGetConfig".}
|
|
||||||
proc glXGetCurrentContext*(): GLXContext{.cdecl, dynlib: dllname,
|
|
||||||
importc: "glXGetCurrentContext".}
|
|
||||||
proc glXGetCurrentDrawable*(): GLXDrawable{.cdecl, dynlib: dllname,
|
|
||||||
importc: "glXGetCurrentDrawable".}
|
|
||||||
proc glXWaitGL*(){.cdecl, dynlib: dllname, importc: "glXWaitGL".}
|
|
||||||
proc glXWaitX*(){.cdecl, dynlib: dllname, importc: "glXWaitX".}
|
|
||||||
proc glXUseXFont*(font: XFont, first, count, list: int){.cdecl, dynlib: dllname,
|
|
||||||
importc: "glXUseXFont".}
|
|
||||||
# GLX 1.1 and later
|
|
||||||
proc glXQueryExtensionsString*(dpy: PDisplay, screen: int): cstring{.cdecl,
|
|
||||||
dynlib: dllname, importc: "glXQueryExtensionsString".}
|
|
||||||
proc glXQueryServerString*(dpy: PDisplay, screen, name: int): cstring{.cdecl,
|
|
||||||
dynlib: dllname, importc: "glXQueryServerString".}
|
|
||||||
proc glXGetClientString*(dpy: PDisplay, name: int): cstring{.cdecl,
|
|
||||||
dynlib: dllname, importc: "glXGetClientString".}
|
|
||||||
# Mesa GLX Extensions
|
|
||||||
proc glXCreateGLXPixmapMESA*(dpy: PDisplay, visual: PXVisualInfo,
|
|
||||||
pixmap: XPixmap, cmap: XColormap): GLXPixmap{.
|
|
||||||
cdecl, dynlib: dllname, importc: "glXCreateGLXPixmapMESA".}
|
|
||||||
proc glXReleaseBufferMESA*(dpy: PDisplay, d: GLXDrawable): bool{.cdecl,
|
|
||||||
dynlib: dllname, importc: "glXReleaseBufferMESA".}
|
|
||||||
proc glXCopySubBufferMESA*(dpy: PDisplay, drawbale: GLXDrawable,
|
|
||||||
x, y, width, height: int){.cdecl, dynlib: dllname,
|
|
||||||
importc: "glXCopySubBufferMESA".}
|
|
||||||
proc glXGetVideoSyncSGI*(counter: var int32): int{.cdecl, dynlib: dllname,
|
|
||||||
importc: "glXGetVideoSyncSGI".}
|
|
||||||
proc glXWaitVideoSyncSGI*(divisor, remainder: int, count: var int32): int{.
|
|
||||||
cdecl, dynlib: dllname, importc: "glXWaitVideoSyncSGI".}
|
|
||||||
# implementation
|
|
||||||
File diff suppressed because it is too large
Load diff
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue