Some macros used in wNim.
Types
wNilAccess = object of Defect
Macros
macro property(x: untyped): untyped
- Add property macro to proc as pragma so that getters/setters can access as nim's style.
macro validate(x: untyped): untyped
- Add validate macro to a proc as pragma to ensure self is not nil.
macro shield(x: untyped): untyped
- Add export marker to proc but hide it in the document. Used internally.
macro wClass(name: untyped; body: untyped): untyped
-
A macro for building class following wNim's naming convention. The user can use wClass to subclass the built-in classes in wNim. Constructor is generated from initializer automatically. final() proc is optional. If provided, it will be called when the object being destroyed automatically. In final() proc, it don't need to call final() in superclass.
Example:
wClass(wMyFrame of wFrame): proc final(self: wMyFrame) = echo "release some resource..." proc init(self: wMyFrame) = wFrame(self).init() proc init(self: wMyFrame, title: string) = wFrame(self).init(title=title)
Output:
when not declared(wMyFrame): type wMyFrame = ref object of wFrame proc init(self: wMyFrame) = wFrame(self).init() proc MyFrame(): wMyFrame {.inline, discardable.} = new(result) result.init() proc init(self: wMyFrame; title: string) = wFrame(self).init(title=title) proc MyFrame(title: string): wMyFrame {.inline, discardable.} = new(result) result.init(title)
macro wEventRegister(event, list: untyped): untyped
-
A macro to register event message ID so that the Event() constructor can return the corresponding object of the class. The event class must be the subclass of the wEvent. For example:
type wMyLinkEvent = ref object of wCommandEvent wEventRegister(wMyLinkEvent): wEvent_OpenUrl var e = Event(msg=wEvent_OpenUrl) doAssert(e of wMyLinkEvent)
Templates
template releaseOrDestroy(T: typedesc; P: typedesc; hasFinal: bool): untyped
- Used internally.
template wValidate(vargs: varargs[(pointer, string), wValidateToPointer]): untyped
- Used internally.