std/with support field assign (#14484)
* std/with support filed assign * add changelog * add support x.dup.with * add example * revert support x.dup.with; add example * update changelog; fix assignment in parameter * Update changelog.md * add example for assignment in parameter * Remove colon style assign Co-authored-by: Clyybber <darkmine956@gmail.com>
This commit is contained in:
parent
957bf15a08
commit
ba042af9cc
4 changed files with 59 additions and 12 deletions
|
|
@ -41,6 +41,7 @@ when isMainModule:
|
|||
type
|
||||
Foo = object
|
||||
col, pos: string
|
||||
name: string
|
||||
|
||||
proc setColor(f: var Foo; r, g, b: int) = f.col = $(r, g, b)
|
||||
proc setPosition(f: var Foo; x, y: float) = f.pos = $(x, y)
|
||||
|
|
@ -49,3 +50,9 @@ when isMainModule:
|
|||
with(f, setColor(2, 3, 4), setPosition(0.0, 1.0))
|
||||
echo f
|
||||
|
||||
f = Foo()
|
||||
with f:
|
||||
col = $(2, 3, 4)
|
||||
pos = $(0.0, 1.0)
|
||||
_.name = "bar"
|
||||
echo f
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue