Skip to content

Commit

Permalink
add test for #13828
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Aug 17, 2024
1 parent cb3fcd5 commit e94a8da
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/template/mexport.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import macros

type
Storage[N: static[int]] = array[N, float32]
Quat* = object
data*: Storage[4]

proc `[]`(q: Quat, index: int): float32 = q.data[index]
proc `[]=`(q: var Quat, index: int, value: float32) = q.data[index] = value

template genAccessor(t, a, i): untyped =
template a*(q: t): float32 {.inject.} = q[i]
template `a=`*(q: var t, value: float32) {.inject.} = q[i] = value

genAccessor Quat, w, 0
genAccessor Quat, x, 1
genAccessor Quat, y, 2
expandMacros:
genAccessor Quat, z, 3
9 changes: 9 additions & 0 deletions tests/template/texport.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# issue #13828

import mexport

var a = Quat()
a.data = [1f,2,3,4]
a.x = 42.0
doAssert a.x == 42
doAssert a.z == 4

0 comments on commit e94a8da

Please sign in to comment.