diff options
| author | Amir Rajan <[email protected]> | 2021-09-06 14:32:04 -0500 |
|---|---|---|
| committer | Amir Rajan <[email protected]> | 2021-09-06 14:34:34 -0500 |
| commit | 2f5eb6ab368b062dbbde39b3cee6eae23c5452ff (patch) | |
| tree | e2f0b5f4a1ab4919cf5669f6187994489411821a /samples/12_c_extensions/README.md | |
| parent | aa8d3ac4bdccf522b8082a7fa7d595be2bd54b7d (diff) | |
| download | dragonruby-game-toolkit-contrib-2f5eb6ab368b062dbbde39b3cee6eae23c5452ff.tar.gz dragonruby-game-toolkit-contrib-2f5eb6ab368b062dbbde39b3cee6eae23c5452ff.zip | |
Synced with version 2.26
Diffstat (limited to 'samples/12_c_extensions/README.md')
| -rw-r--r-- | samples/12_c_extensions/README.md | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/samples/12_c_extensions/README.md b/samples/12_c_extensions/README.md index 8950e53..aef3864 100644 --- a/samples/12_c_extensions/README.md +++ b/samples/12_c_extensions/README.md @@ -350,6 +350,34 @@ dragonruby-bind --ffi-module=CoolStuff bridge.c Then one can use `include FFI::CoolStuff` instead. +### Type checks + +C extensions expect the right types in the right place! + +Given the following C code: + +```c +void take_int(int x) { ... } +void take_struct(struct S) { ... } +``` + +the next calls from the Ruby side + +```ruby +take_int(15.0) +take_struct(42) +``` + +may not work as you would expect. +In the case of `take_int`, you'll likely see some garbage instead of "expected" `15`. +The call to `take_struct` will likely crash. + +To prevent this from happening, `dragonruby-bind` emits code that does type checking: +if you use the wrong types DragonRuby will throw an exception. + +If the type checking takes CPU cycles out of your game (or if you feel brave) you can +disable type checks via `--no-typecheck` CLI argument when emitting C bindings. + ### Pitfalls There is no so-called marshalling when it comes to structs. When you read or |
