Is there a way to check an object type for a custom pragma?
In the manual there's an example of a custom annotation on a type, but it isn't (https://nim-lang.org/docs/manual.html#implementation-specific-pragmas-custom-annotations ):
const tblspace {.strdefine.} = "dev" # switch for dev, test and prod environments:
type
User {.dbTable("users", tblspace).} = object
id {.dbKey(primary_key = true).}: int
name {.dbKey"full_name".}: string
is_cached {.dbIgnore.}: bool
age: int
UserProfile {.dbTable("profiles", tblspace).} = object
id {.dbKey(primary_key = true).}: int
user_id {.dbForeignKey: User.}: int
read_access: bool
write_access: bool
admin_acess: bool
I tried using hasCustomPragma but it only works for fields and procs. Then I tried using getImpl but it only includes the pragmas on the fields and ignores the pragmas on the type itself.
Am I doing something wrong and there is a way to do this, or is this a bug?
Looks like a bug, type pragmas are not seen on the user side
type
User {.exportc, packed.} = object
id: int
import macros
macro test(t: typedesc): untyped =
echo t.getType()[1].symbol.getImpl.treerepr
test(User)
gives
TypeDef
Sym "User"
Empty
ObjectTy
Empty
Empty
RecList
IdentDefs
Ident ident"id"
Sym "int"
Empty
no pragmas to be found