Nim 2.0.8 Manual{.emit: """/*TYPESECTION*/ struct Vector3 { public: Vector3(): x(5) {} Vector3(float x_): x(x_) {} float x; }; """.} type Vector3 {.importcpp: "Vector3", nodecl} = object x: cfloat proc proc constructVector3(a: cfloat): Vector3 {.importcpp: "Vector3(@)", nodecl} # Horrible example of how to interface with a C++ engine ... ;-) {.link: "/usr/lib/libIrrlicht.so".} {.emit: """ using namespace double> x; x[6] = 91.4; type VectorIterator[T] {.importcpp: "std::vector<'0>::iterator".} = object var x: VectorIterator[cint] std::vector::iterator x; ImportObjC pragma Similar to the importc pragma 0 码力 | 132 页 | 5.73 MB | 1 年前3
Nim 2.0.2 中文手册集合基础类型的最⼤区间⻓度为 MaxSetElements ,⽬前始终为 2^16。具有更⼤区间⻓ 度的类型将被强制转换为区间 0 .. MaxSetElements-1 。 原因是集合被实现为⾼性能的bit vector。 试图⽤太⼤类型来声明集合将导致⼀个错误: 注意: Nim 还提供了 hash sets (sets.html) (你需要通过 import std/sets 导⼊它们),它们没有这样的限制。 {.emit: """/*TYPESECTION*/ struct Vector3 { public: Vector3(): x(5) {} Vector3(float x_): x(x_) {} float x; }; """.} type Vector3 {.importcpp: "Vector3", nodecl} = object x: cfloat proc proc constructVector3(a: cfloat): Vector3 {.importcpp: "Vector3(@)", nodecl} 与 C 语⾔的importc 编译指示类似, importcpp 编译指示可以⽤来导⼊ C++ ⽅法或⼀般的 C++ 标识符。 ⽣成的代码使⽤ C++ 的⽅ 法调⽤语法: obj->method(arg) 。 与 header 和 emit0 码力 | 127 页 | 7.05 MB | 1 年前3
Computer Programming with the Nim Programming Language
graphic animations; that is, 32- or even 16-bit. Modern CPUs often also have some form of support for vector data types to process multiple values in one instruction (SIMD, single instruction, multiple data) generation of math operations for custom data types. Let us assume that we have created a custom Vector object, for which we have to define addition and subtraction operations. Instead of writing code math operator as untyped parameter: type Vector = object x, y, z: int template genOp(op: untyped) = proc `op`(a, b: Vector): Vector = Vector(x: `op`(a.x, b.x), y: `op`(a.y, b.y), z: `op`(a0 码力 | 865 页 | 7.45 MB | 1 年前3
Computer Programming with the Nim Programming Language
graphic animations; that is, 32- or even 16-bit. Modern CPUs often also have some form of support for vector data types to process multiple values in one instruction (SIMD, single instruction, multiple data) generation of math operations for custom data types. Let us assume that we have created a custom Vector object, for which we have to define addition and subtraction operations. Instead of writing code math operator as untyped parameter: type Vector = object x, y, z: int template genOp(op: untyped) = proc `op`(a, b: Vector): Vector = Vector(x: `op`(a.x, b.x), y: `op`(a.y, b.y), z: `op`(a0 码力 | 784 页 | 2.13 MB | 1 年前3
Computer Programming with the Nim Programming Languagegraphic animations; that is, 32- or even 16-bit. Modern CPUs often also have some form of support for vector data types to process multiple values in one instruction (SIMD, sin gle instruction, multiple data) generation of math opera tions for custom data types. Let us assume that we have created a custom Vector object, for which we have to define addition and subtraction operations. Instead of writing code operator as untyped parameter: type 190 Vector = object x, y, z: int template genOp(op: untyped) = proc `op`(a, b: Vector): Vector = Vector(x: `op`(a.x, b.x), y: `op`(a.y, b.y), z: `op`(a0 码力 | 512 页 | 3.54 MB | 1 年前3
Computer Programming with the Nim Programming Languageani mations; that is, 32- or even 16-bit. Modern CPUs often also have some form of support for vector data types to process multiple values in one instruction (SIMD, single instruction, multiple data) generation of math operations for custom data types. Let us assume that we have created a custom Vector object, for which we have to define addition and subtraction operations. Instead of writing code operator as untyped parameter: type 187 Vector = object x, y, z: int template genOp(op: untyped) = proc `op`(a, b: Vector): Vector = Vector(x: `op`(a.x, b.x), y: `op`(a.y, b.y), z: `op`(a0 码力 | 508 页 | 3.50 MB | 1 年前3
Computer Programming with the Nim Programming Languagegraphic animations; that is, 32- or even 16-bit. Modern CPUs often also have some form of support for vector data types to process multiple values in one instruction (SIMD, sin gle instruction, multiple data) generation of math opera tions for custom data types. Let us assume that we have created a custom Vector object, for which we have to define addition and subtraction operations. Instead of writing code operator as untyped parameter: type 190 Vector = object x, y, z: int template genOp(op: untyped) = proc `op`(a, b: Vector): Vector = Vector(x: `op`(a.x, b.x), y: `op`(a.y, b.y), z: `op`(a0 码力 | 512 页 | 3.53 MB | 1 年前3
Computer Programming with the Nim Programming Languageani mations; that is, 32- or even 16-bit. Modern CPUs often also have some form of support for vector data types to process multiple values in one instruction (SIMD, single instruction, multiple data) generation of math operations for custom data types. Let us assume that we have created a custom Vector object, for which we have to define addition and subtraction operations. Instead of writing code operator as untyped parameter: type 187 Vector = object x, y, z: int template genOp(op: untyped) = proc `op`(a, b: Vector): Vector = Vector(x: `op`(a.x, b.x), y: `op`(a.y, b.y), z: `op`(a0 码力 | 508 页 | 3.54 MB | 1 年前3
Computer Programming with the Nim Programming Languageani mations; that is, 32- or even 16-bit. Modern CPUs often also have some form of support for vector data types to process multiple values in one instruction (SIMD, single instruction, multiple data) generation of math operations for custom data types. Let us assume that we have created a custom Vector object, for which we have to define addition and subtraction operations. Instead of writing code operator as untyped parameter: type 187 Vector = object x, y, z: int template genOp(op: untyped) = proc `op`(a, b: Vector): Vector = Vector(x: `op`(a.x, b.x), y: `op`(a.y, b.y), z: `op`(a0 码力 | 508 页 | 3.50 MB | 1 年前3
Computer Programming with the Nim Programming Languageani mations; that is, 32- or even 16-bit. Modern CPUs often also have some form of support for vector data types to process multiple values in one instruction (SIMD, single instruction, multiple data) generation of math operations for custom data types. Let us assume that we have created a custom Vector object, for which we have to define addition and subtraction operations. Instead of writing code operator as untyped parameter: type 187 Vector = object x, y, z: int template genOp(op: untyped) = proc `op`(a, b: Vector): Vector = Vector(x: `op`(a.x, b.x), y: `op`(a.y, b.y), z: `op`(a0 码力 | 508 页 | 3.52 MB | 1 年前3
共 32 条
- 1
- 2
- 3
- 4













