new feature: package level objects
This commit is contained in:
parent
7889692523
commit
c17f6c7837
9 changed files with 93 additions and 11 deletions
3
tests/package_level_objects/definefoo.nim
Normal file
3
tests/package_level_objects/definefoo.nim
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
type
|
||||
Foo* {.package.} = object
|
||||
x, y: int
|
||||
0
tests/package_level_objects/mypackage.nimble
Normal file
0
tests/package_level_objects/mypackage.nimble
Normal file
16
tests/package_level_objects/tusefoo.nim
Normal file
16
tests/package_level_objects/tusefoo.nim
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
discard """
|
||||
output: '''@[(x: 3, y: 4)]'''
|
||||
"""
|
||||
|
||||
type
|
||||
mypackage.Foo = object
|
||||
Other = proc (inp: Foo)
|
||||
|
||||
import definefoo
|
||||
|
||||
# after this import, Foo is a completely resolved type, so
|
||||
# we can create a sequence of it:
|
||||
var s: seq[Foo] = @[]
|
||||
|
||||
s.add Foo(x: 3, y: 4)
|
||||
echo s
|
||||
19
tests/package_level_objects/tusefoo2.nim
Normal file
19
tests/package_level_objects/tusefoo2.nim
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
discard """
|
||||
output: '''compiles'''
|
||||
"""
|
||||
|
||||
# Test that the object type does not need to be resolved at all:
|
||||
|
||||
type
|
||||
mypackage.Foo = object
|
||||
Other = proc (inp: Foo)
|
||||
|
||||
Node = ref object
|
||||
external: ptr Foo
|
||||
data: string
|
||||
|
||||
var x: Node
|
||||
new(x)
|
||||
x.data = "compiles"
|
||||
|
||||
echo x.data
|
||||
Loading…
Add table
Add a link
Reference in a new issue