summaryrefslogtreecommitdiffhomepage
path: root/samples/12_c_extensions/README.md
diff options
context:
space:
mode:
author_Tradam <[email protected]>2021-12-16 19:22:26 -0500
committerGitHub <[email protected]>2021-12-16 19:22:26 -0500
commit5954b9beb4d4a3b4f248d72d1851195f030558a8 (patch)
treefecd8aa840a25afdb502915b0fdb4d03b7ed339a /samples/12_c_extensions/README.md
parent2f845281f133849256b57bb08fd3e9ae57600784 (diff)
parenteaa29e72939f5edf61735ccbb73c36ee89369f65 (diff)
downloaddragonruby-game-toolkit-contrib-5954b9beb4d4a3b4f248d72d1851195f030558a8.tar.gz
dragonruby-game-toolkit-contrib-5954b9beb4d4a3b4f248d72d1851195f030558a8.zip
Merge branch 'DragonRuby:master' into masterHEADmaster
Diffstat (limited to 'samples/12_c_extensions/README.md')
-rw-r--r--samples/12_c_extensions/README.md28
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