nimrod

Nim如何与C/C++/Objc互动

痞子三分冷 提交于 2020-03-14 02:30:00
header pragma(头文件指示): type PFile {.importc: "FILE*", header: "<stdio.h>".} = distinct pointer # 导入c语言的 FILE* 指针类型到Nim里用PFile新类型来代替使用. Compile pragma(编译指示): 直接让nim文件使用c/c++代码文件, 编译的时候会先编译.c文件成.o然后链接让nim也能使用其内容. #test.nim {.compile: "testc.c".} proc csum(n: cint): cint {.importc.} echo csum(100) //testc.c int csum(int n) { return n + 10; } Link pragma(连接指示): 直接链接obj文件. {.link: "test.o".} PassC pragma(编译参数指示): 类似makefile compile flag: -g -Wall {.passC: "-Wall -Werror".} #也可使用外部程序指令 {.passC: gorge("pkg-config --cflags sdl").} PassL pragma(连接参数指示): 类似makefile link flag: -L/xxx/sdl -lsdl {.passL: "

How do I parse a string at compile time in Nimrod?

你。 提交于 2019-12-06 03:11:01
问题 Going through the second part of Nimrod's tutorial I've reached the part were macros are explained. The documentation says they run at compile time, so I thought I could do some parsing of strings to create myself a domain specific language. However, there are no examples of how to do this, the debug macro example doesn't display how one deals with a string parameter. I want to convert code like: instantiate(""" height,f,132.4 weight,f,75.0 age,i,25 """) …into something which by hand I would

How do I parse a string at compile time in Nimrod?

风流意气都作罢 提交于 2019-12-04 07:34:43
Going through the second part of Nimrod's tutorial I've reached the part were macros are explained. The documentation says they run at compile time, so I thought I could do some parsing of strings to create myself a domain specific language. However, there are no examples of how to do this, the debug macro example doesn't display how one deals with a string parameter. I want to convert code like: instantiate(""" height,f,132.4 weight,f,75.0 age,i,25 """) …into something which by hand I would write like: var height: float = 132.4 var weight: float = 75.0 var age: int = 25 Obviously this example