Created
October 8, 2020 14:42
-
-
Save fccm/7d3a18bb964436e1840167112b22d78a to your computer and use it in GitHub Desktop.
ocaml-sfml without naked pointers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/examples/ex_rect.sh b/examples/ex_rect.sh | |
index a5a1492..2d8b14e 100755 | |
--- a/examples/ex_rect.sh | |
+++ b/examples/ex_rect.sh | |
@@ -1,4 +1,5 @@ | |
ocaml bigarray.cma \ | |
+ -I ../src \ | |
sfml_system.cma \ | |
sfml_window.cma \ | |
sfml_graphics.cma \ | |
diff --git a/src/cxx_stubs/SFCircleShape_stub.cpp b/src/cxx_stubs/SFCircleShape_stub.cpp | |
index b4e23bd..932e5f1 100644 | |
--- a/src/cxx_stubs/SFCircleShape_stub.cpp | |
+++ b/src/cxx_stubs/SFCircleShape_stub.cpp | |
@@ -29,6 +29,16 @@ | |
#include "SFCircleShape_stub.hpp" | |
#include "SFColor_stub.hpp" | |
+value Val_sfCircleShape(sf::CircleShape * cs) | |
+{ | |
+ return caml_copy_nativeint((intnat) cs); | |
+} | |
+ | |
+sf::CircleShape * SfCircleShape_val(value cs) | |
+{ | |
+ return (sf::CircleShape *) Nativeint_val(cs); | |
+} | |
+ | |
CAMLextern_C value | |
caml_sfCircleShape_create(value radius, value pointCount, value unit) | |
{ | |
diff --git a/src/cxx_stubs/SFCircleShape_stub.hpp b/src/cxx_stubs/SFCircleShape_stub.hpp | |
index 7b60c57..a1c6fdc 100644 | |
--- a/src/cxx_stubs/SFCircleShape_stub.hpp | |
+++ b/src/cxx_stubs/SFCircleShape_stub.hpp | |
@@ -3,8 +3,8 @@ | |
#include <SFML/Graphics/CircleShape.hpp> | |
-#define Val_sfCircleShape(cs) ((value)(cs)) | |
-#define SfCircleShape_val(cs) ((sf::CircleShape *)(cs)) | |
+value Val_sfCircleShape(sf::CircleShape * cs); | |
+sf::CircleShape * SfCircleShape_val(value cs); | |
#define SfCircleShape_val_u(shape) \ | |
SfCircleShape_val(Field(shape,0)) | |
diff --git a/src/cxx_stubs/SFContext_stub.cpp b/src/cxx_stubs/SFContext_stub.cpp | |
index 85b2b82..fcc4918 100644 | |
--- a/src/cxx_stubs/SFContext_stub.cpp | |
+++ b/src/cxx_stubs/SFContext_stub.cpp | |
@@ -27,8 +27,15 @@ | |
#include "sf_caml_conv.hpp" | |
#include "sf_context_settings.hpp" | |
-#define Val_sfContext(ctx) ((value)(ctx)) | |
-#define SfContext_val(ctx) ((sf::Context *)(ctx)) | |
+static value Val_sfContext(sf::Context * ctx) | |
+{ | |
+ return caml_copy_nativeint((intnat) ctx); | |
+} | |
+ | |
+static sf::Context * SfContext_val(value ctx) | |
+{ | |
+ return (sf::Context *) Nativeint_val(ctx); | |
+} | |
/* sf::Context */ | |
diff --git a/src/cxx_stubs/SFCursor_stub.cpp b/src/cxx_stubs/SFCursor_stub.cpp | |
index 403172b..277e052 100644 | |
--- a/src/cxx_stubs/SFCursor_stub.cpp | |
+++ b/src/cxx_stubs/SFCursor_stub.cpp | |
@@ -1,6 +1,6 @@ | |
/* | |
* OCaml-SFML - OCaml bindings for the SFML library. | |
- * Copyright (C) 2012 Florent Monnier <monnier.florent(_)gmail.com> | |
+ * Copyright (C) 2018 Sylvain Boilard <boilard(_)crans.org> | |
* | |
* This software is provided 'as-is', without any express or implied warranty. | |
* In no event will the authors be held liable for any damages arising from the | |
@@ -31,39 +31,45 @@ | |
void | |
caml_sfCursor_destroy(value cursor) | |
{ | |
- delete SfCursor_val(cursor); | |
+ delete SfCursor_val(cursor); | |
} | |
CAMLextern_C value | |
caml_sfCursor_loadFromPixels(value data, value size, value hotspot) | |
{ | |
- CAMLparam3(data, size, hotspot); | |
- sf::Cursor* cursor = new sf::Cursor; | |
+ CAMLparam3(data, size, hotspot); | |
+ CAMLlocal1(ml_cursor); | |
- if (!cursor->loadFromPixels((const sf::Uint8*)String_val(data), SfVector2u_val(size), SfVector2u_val(hotspot))) | |
- { | |
- delete cursor; | |
- caml_failwith("SFCursor.loadFromPixels"); | |
- } | |
- CAMLlocal1(ml_cursor); | |
- ml_cursor = caml_alloc_final(2, caml_sfCursor_destroy, 0, 1); | |
- SfCursor_val(ml_cursor) = cursor; | |
- return ml_cursor; | |
+ sf::Cursor* cursor = new sf::Cursor; | |
+ | |
+ if (!cursor->loadFromPixels((const sf::Uint8*)String_val(data), SfVector2u_val(size), SfVector2u_val(hotspot))) | |
+ { | |
+ delete cursor; | |
+ caml_failwith("SFCursor.loadFromPixels"); | |
+ } | |
+ ml_cursor = caml_alloc_final(2, caml_sfCursor_destroy, 0, 1); | |
+ SfCursor_val(ml_cursor) = cursor; | |
+ | |
+ CAMLreturn(ml_cursor); | |
} | |
CAMLextern_C value | |
caml_sfCursor_loadFromSystem(value type) | |
{ | |
- CAMLparam1(type); | |
- sf::Cursor* cursor = new sf::Cursor; | |
+ CAMLparam1(type); | |
+ CAMLlocal1(ml_cursor); | |
+ | |
+ sf::Cursor* cursor = new sf::Cursor; | |
- if (!cursor->loadFromSystem((sf::Cursor::Type)Long_val(type))) | |
- { | |
- delete cursor; | |
- caml_failwith("SFCursor.loadFromSystem"); | |
- } | |
- CAMLlocal1(ml_cursor); | |
- ml_cursor = caml_alloc_final(2, caml_sfCursor_destroy, 0, 1); | |
- SfCursor_val(ml_cursor) = cursor; | |
- return ml_cursor; | |
+ if (!cursor->loadFromSystem((sf::Cursor::Type)Long_val(type))) | |
+ { | |
+ delete cursor; | |
+ caml_failwith("SFCursor.loadFromSystem"); | |
+ } | |
+ ml_cursor = caml_alloc_final(2, caml_sfCursor_destroy, 0, 1); | |
+ SfCursor_val(ml_cursor) = cursor; | |
+ | |
+ CAMLreturn(ml_cursor); | |
} | |
+ | |
+// vim: sw=4 sts=4 ts=4 et | |
diff --git a/src/cxx_stubs/SFFont_stub.cpp b/src/cxx_stubs/SFFont_stub.cpp | |
index 074b373..110e64f 100644 | |
--- a/src/cxx_stubs/SFFont_stub.cpp | |
+++ b/src/cxx_stubs/SFFont_stub.cpp | |
@@ -27,6 +27,16 @@ | |
#include "SFFont_stub.hpp" | |
#include "SFRect_stub.hpp" | |
+value Val_sfFont(sf::Font * p) | |
+{ | |
+ return caml_copy_nativeint((intnat) p); | |
+} | |
+ | |
+sf::Font * SfFont_val(value v) | |
+{ | |
+ return (sf::Font *) Nativeint_val(v); | |
+} | |
+ | |
/* sf::Font */ | |
CAMLextern_C value | |
diff --git a/src/cxx_stubs/SFFont_stub.hpp b/src/cxx_stubs/SFFont_stub.hpp | |
index 8452f32..8f75bd6 100644 | |
--- a/src/cxx_stubs/SFFont_stub.hpp | |
+++ b/src/cxx_stubs/SFFont_stub.hpp | |
@@ -4,8 +4,8 @@ | |
#include <SFML/Graphics/Font.hpp> | |
-#define Val_sfFont(fnt) ((value)(fnt)) | |
-#define SfFont_val(fnt) ((sf::Font *)(fnt)) | |
+value Val_sfFont(sf::Font * p); | |
+sf::Font * SfFont_val(value v); | |
#define SfFont_val_u(font) \ | |
SfFont_val(Field(font,0)) | |
diff --git a/src/cxx_stubs/SFFtp_stub.cpp b/src/cxx_stubs/SFFtp_stub.cpp | |
index 49c30f4..76a3c74 100644 | |
--- a/src/cxx_stubs/SFFtp_stub.cpp | |
+++ b/src/cxx_stubs/SFFtp_stub.cpp | |
@@ -158,17 +158,17 @@ Val_sfFtpTransferMode(sf::Ftp::TransferMode e) | |
caml_failwith("SFFtp.transferMode"); | |
} | |
-#define Val_sfFtp(ftp) ((value)(ftp)) | |
-#define SfFtp_val(ftp) ((sf::Ftp *)(ftp)) | |
+static value Val_sfFtp(sf::Ftp * p) { return caml_copy_nativeint((intnat) p); } | |
+static sf::Ftp * SfFtp_val(value v) { return (sf::Ftp *) Nativeint_val(v); } | |
-#define Val_sfFtpResponse(res) ((value)(res)) | |
-#define SfFtpResponse_val(res) ((sf::Ftp::Response *)(res)) | |
+static value Val_sfFtpResponse(sf::Ftp::Response * p) { return caml_copy_nativeint((intnat) p); } | |
+static sf::Ftp::Response * SfFtpResponse_val(value v) { return (sf::Ftp::Response *) Nativeint_val(v); } | |
-#define Val_sfFtpDirectoryResponse(fdr) ((value)(fdr)) | |
-#define SfFtpDirectoryResponse_val(fdr) ((sf::Ftp::DirectoryResponse *)(fdr)) | |
+static value Val_sfFtpDirectoryResponse(sf::Ftp::DirectoryResponse * p) { return caml_copy_nativeint((intnat) p); } | |
+static sf::Ftp::DirectoryResponse * SfFtpDirectoryResponse_val(value v) { return (sf::Ftp::DirectoryResponse *) Nativeint_val(v); } | |
-#define Val_sfFtpListingResponse(flr) ((value)(flr)) | |
-#define SfFtpListingResponse_val(flr) ((sf::Ftp::ListingResponse *)(flr)) | |
+static value Val_sfFtpListingResponse(sf::Ftp::ListingResponse * p) { return caml_copy_nativeint((intnat) p); } | |
+static sf::Ftp::ListingResponse * SfFtpListingResponse_val(value v) { return (sf::Ftp::ListingResponse *) Nativeint_val(v); } | |
CAMLextern_C value | |
diff --git a/src/cxx_stubs/SFHttp_stub.cpp b/src/cxx_stubs/SFHttp_stub.cpp | |
index 49c5195..60abcbc 100644 | |
--- a/src/cxx_stubs/SFHttp_stub.cpp | |
+++ b/src/cxx_stubs/SFHttp_stub.cpp | |
@@ -70,14 +70,14 @@ static value Val_sfHttpStatus(sf::Http::Response::Status status) | |
caml_failwith("SFHttp.status"); | |
} | |
-#define Val_sfHttpRequest(req) ((value)(req)) | |
-#define SfHttpRequest_val(req) ((sf::Http::Request *)(req)) | |
+static value Val_sfHttpRequest(sf::Http::Request * p) { return caml_copy_nativeint((intnat) p); } | |
+static sf::Http::Request * SfHttpRequest_val(value v) { return (sf::Http::Request *) Nativeint_val(v); } | |
-#define Val_sfHttpResponse(req) ((value)(req)) | |
-#define SfHttpResponse_val(req) ((sf::Http::Response *)(req)) | |
+static value Val_sfHttpResponse(sf::Http::Response * p) { return caml_copy_nativeint((intnat) p); } | |
+static sf::Http::Response * SfHttpResponse_val(value v) { return (sf::Http::Response *) Nativeint_val(v); } | |
-#define Val_sfHttp(req) ((value)(req)) | |
-#define SfHttp_val(req) ((sf::Http *)(req)) | |
+static value Val_sfHttp(sf::Http * p) { return caml_copy_nativeint((intnat) p); } | |
+static sf::Http * SfHttp_val(value v) { return (sf::Http *) Nativeint_val(v); } | |
CAMLextern_C value | |
caml_sfHttpRequest_create(value unit) | |
diff --git a/src/cxx_stubs/SFImage_stub.cpp b/src/cxx_stubs/SFImage_stub.cpp | |
index 4f85a41..e9e481c 100644 | |
--- a/src/cxx_stubs/SFImage_stub.cpp | |
+++ b/src/cxx_stubs/SFImage_stub.cpp | |
@@ -30,6 +30,16 @@ | |
#include <cstring> | |
+value Val_sfImage(sf::Image * p) | |
+{ | |
+ return caml_copy_nativeint((intnat) p); | |
+} | |
+ | |
+sf::Image * SfImage_val(value v) | |
+{ | |
+ return (sf::Image *) Nativeint_val(v); | |
+} | |
+ | |
/* sf::Image */ | |
diff --git a/src/cxx_stubs/SFImage_stub.hpp b/src/cxx_stubs/SFImage_stub.hpp | |
index 298c9b4..bcc3fe1 100644 | |
--- a/src/cxx_stubs/SFImage_stub.hpp | |
+++ b/src/cxx_stubs/SFImage_stub.hpp | |
@@ -3,8 +3,8 @@ | |
#include <SFML/Graphics/Image.hpp> | |
-#define Val_sfImage(img) ((value)(img)) | |
-#define SfImage_val(img) ((sf::Image *)(img)) | |
+value Val_sfImage(sf::Image * p); | |
+sf::Image * SfImage_val(value v); | |
#define SfImage_val_u(img) \ | |
diff --git a/src/cxx_stubs/SFJoystick_stub.cpp b/src/cxx_stubs/SFJoystick_stub.cpp | |
index 02efb29..5a301d5 100644 | |
--- a/src/cxx_stubs/SFJoystick_stub.cpp | |
+++ b/src/cxx_stubs/SFJoystick_stub.cpp | |
@@ -139,9 +139,10 @@ CAMLextern_C value | |
caml_sfJoystick_getIdentification(value ml_joystick) | |
{ | |
CAMLparam0(); | |
+ CAMLlocal1(ident); | |
sf::Joystick::Identification sf_ident = sf::Joystick::getIdentification(Unsigned_int_val(ml_joystick)); | |
- CAMLlocal1(ident); | |
+ | |
ident = caml_alloc_tuple(3); | |
Store_field(ident, 0, caml_copy_string(sf_ident.name.toAnsiString().c_str())); | |
Store_field(ident, 1, caml_copy_nativeint(sf_ident.vendorId)); | |
diff --git a/src/cxx_stubs/SFMusic_stub.cpp b/src/cxx_stubs/SFMusic_stub.cpp | |
index 95b4110..b24f1aa 100644 | |
--- a/src/cxx_stubs/SFMusic_stub.cpp | |
+++ b/src/cxx_stubs/SFMusic_stub.cpp | |
@@ -27,8 +27,8 @@ | |
#include "sf_conv_vectors.hpp" | |
#include "SFTime_stub.hpp" | |
-#define Val_sfMusic(music) ((value)(music)) | |
-#define SfMusic_val(music) ((sf::Music *)(music)) | |
+static value Val_sfMusic(sf::Music * p) { return caml_copy_nativeint((intnat) p); } | |
+static sf::Music * SfMusic_val(value v) { return (sf::Music *) Nativeint_val(v); } | |
static value | |
Val_sfMusicStatus(sf::Music::Status sndst) | |
diff --git a/src/cxx_stubs/SFPacket_stub.cpp b/src/cxx_stubs/SFPacket_stub.cpp | |
index 49ec683..50442b3 100644 | |
--- a/src/cxx_stubs/SFPacket_stub.cpp | |
+++ b/src/cxx_stubs/SFPacket_stub.cpp | |
@@ -28,6 +28,17 @@ | |
#include "sf_caml_incs.hpp" | |
#include "SFPacket_stub.hpp" | |
+value Val_sfPacket(sf::Packet * p) | |
+{ | |
+ return caml_copy_nativeint((intnat) p); | |
+} | |
+ | |
+sf::Packet * SfPacket_val(value v) | |
+{ | |
+ return (sf::Packet *) Nativeint_val(v); | |
+} | |
+ | |
+ | |
CAMLextern_C value | |
caml_sfPacket_create(value unit) | |
{ | |
diff --git a/src/cxx_stubs/SFPacket_stub.hpp b/src/cxx_stubs/SFPacket_stub.hpp | |
index a173bd9..f6cfc66 100644 | |
--- a/src/cxx_stubs/SFPacket_stub.hpp | |
+++ b/src/cxx_stubs/SFPacket_stub.hpp | |
@@ -4,8 +4,8 @@ | |
#include <SFML/Network/Packet.hpp> | |
#include "sf_caml_incs.hpp" | |
-#define Val_sfPacket(pkt) ((value)(pkt)) | |
-#define SfPacket_val(pkt) ((sf::Packet *)(pkt)) | |
+value Val_sfPacket(sf::Packet * p); | |
+sf::Packet * SfPacket_val(value v); | |
#define SfPacket_val_u(pkt) \ | |
SfPacket_val(Field(pkt,0)) | |
diff --git a/src/cxx_stubs/SFRectangleShape_stub.cpp b/src/cxx_stubs/SFRectangleShape_stub.cpp | |
index 30efbca..76cd825 100644 | |
--- a/src/cxx_stubs/SFRectangleShape_stub.cpp | |
+++ b/src/cxx_stubs/SFRectangleShape_stub.cpp | |
@@ -27,8 +27,16 @@ | |
#include "sf_caml_conv.hpp" | |
#include "sf_conv_vectors.hpp" | |
-#define Val_sfRectangleShape(rect) ((value)(rect)) | |
-#define SfRectangleShape_val(rect) ((sf::RectangleShape *)(rect)) | |
+static value Val_sfRectangleShape(sf::RectangleShape * p) | |
+{ | |
+ return caml_copy_nativeint((intnat) p); | |
+} | |
+ | |
+static sf::RectangleShape * SfRectangleShape_val(value v) | |
+{ | |
+ return (sf::RectangleShape *) Nativeint_val(v); | |
+} | |
+ | |
CAMLextern_C value | |
caml_sfRectangleShape_create(value size, value unit) | |
diff --git a/src/cxx_stubs/SFRenderStates_stub.cpp b/src/cxx_stubs/SFRenderStates_stub.cpp | |
index 7481645..b5b75ac 100644 | |
--- a/src/cxx_stubs/SFRenderStates_stub.cpp | |
+++ b/src/cxx_stubs/SFRenderStates_stub.cpp | |
@@ -31,6 +31,16 @@ | |
#include "SFTexture_stub.hpp" | |
#include "SFShader_stub.hpp" | |
+value Val_sfRenderStates(sf::RenderStates * p) | |
+{ | |
+ return caml_copy_nativeint((intnat) p); | |
+} | |
+ | |
+sf::RenderStates * SfRenderStates_val(value v) | |
+{ | |
+ return (sf::RenderStates *) Nativeint_val(v); | |
+} | |
+ | |
/* sf::RenderStates */ | |
CAMLextern_C value | |
diff --git a/src/cxx_stubs/SFRenderStates_stub.hpp b/src/cxx_stubs/SFRenderStates_stub.hpp | |
index c8eb5b7..0bf35c6 100644 | |
--- a/src/cxx_stubs/SFRenderStates_stub.hpp | |
+++ b/src/cxx_stubs/SFRenderStates_stub.hpp | |
@@ -3,7 +3,7 @@ | |
#include <SFML/Graphics/RenderStates.hpp> | |
-#define Val_sfRenderStates(rst) ((value)(rst)) | |
-#define SfRenderStates_val(rst) ((sf::RenderStates *)(rst)) | |
+value Val_sfRenderStates(sf::RenderStates * p); | |
+sf::RenderStates * SfRenderStates_val(value v); | |
#endif // _SF_RENDERSTATES_INC | |
diff --git a/src/cxx_stubs/SFRenderWindow_stub.hpp b/src/cxx_stubs/SFRenderWindow_stub.hpp | |
index da25134..7854649 100644 | |
--- a/src/cxx_stubs/SFRenderWindow_stub.hpp | |
+++ b/src/cxx_stubs/SFRenderWindow_stub.hpp | |
@@ -3,7 +3,14 @@ | |
#include <SFML/Graphics/RenderWindow.hpp> | |
-#define Val_sfRenderWindow(win) ((value)(win)) | |
-#define SfRenderWindow_val(win) ((sf::RenderWindow *)(win)) | |
+static value Val_sfRenderWindow(sf::RenderWindow * p) | |
+{ | |
+ return caml_copy_nativeint((intnat) p); | |
+} | |
+ | |
+static sf::RenderWindow * SfRenderWindow_val(value v) | |
+{ | |
+ return (sf::RenderWindow *) Nativeint_val(v); | |
+} | |
#endif // _SF_RENDERWINDOW_INC | |
diff --git a/src/cxx_stubs/SFShader_stub.cpp b/src/cxx_stubs/SFShader_stub.cpp | |
index 7e19d53..39827f4 100644 | |
--- a/src/cxx_stubs/SFShader_stub.cpp | |
+++ b/src/cxx_stubs/SFShader_stub.cpp | |
@@ -27,6 +27,16 @@ | |
#include "sf_caml_conv.hpp" | |
#include "SFShader_stub.hpp" | |
+value Val_sfShader(sf::Shader * p) | |
+{ | |
+ return caml_copy_nativeint((intnat) p); | |
+} | |
+ | |
+sf::Shader * SfShader_val(value v) | |
+{ | |
+ return (sf::Shader *) Nativeint_val(v); | |
+} | |
+ | |
/* sf::Shader */ | |
CAMLextern_C value | |
diff --git a/src/cxx_stubs/SFShader_stub.hpp b/src/cxx_stubs/SFShader_stub.hpp | |
index 3a617c3..8b038f8 100644 | |
--- a/src/cxx_stubs/SFShader_stub.hpp | |
+++ b/src/cxx_stubs/SFShader_stub.hpp | |
@@ -3,7 +3,7 @@ | |
#include <SFML/Graphics/Shader.hpp> | |
-#define Val_sfShader(shd) ((value)(shd)) | |
-#define SfShader_val(shd) ((sf::Shader *)(shd)) | |
+value Val_sfShader(sf::Shader * p); | |
+sf::Shader * SfShader_val(value v); | |
#endif // _SF_SHADER_INC | |
diff --git a/src/cxx_stubs/SFShape_stub.cpp b/src/cxx_stubs/SFShape_stub.cpp | |
index 3ab2a01..5f3ab8c 100644 | |
--- a/src/cxx_stubs/SFShape_stub.cpp | |
+++ b/src/cxx_stubs/SFShape_stub.cpp | |
@@ -28,6 +28,18 @@ | |
#include "SFShape_stub.hpp" | |
#include "SFColor_stub.hpp" | |
+ | |
+value Val_sfShape(sf::Shape * p) | |
+{ | |
+ return caml_copy_nativeint((intnat) p); | |
+} | |
+ | |
+sf::Shape * SfShape_val(value v) | |
+{ | |
+ return (sf::Shape *) Nativeint_val(v); | |
+} | |
+ | |
+ | |
class sfShapeImpl : public sf::Shape | |
{ | |
public: | |
diff --git a/src/cxx_stubs/SFShape_stub.hpp b/src/cxx_stubs/SFShape_stub.hpp | |
index 80177f1..53fb08c 100644 | |
--- a/src/cxx_stubs/SFShape_stub.hpp | |
+++ b/src/cxx_stubs/SFShape_stub.hpp | |
@@ -3,9 +3,8 @@ | |
#include <SFML/Graphics/Shape.hpp> | |
- | |
-#define Val_sfShape(shp) ((value)(shp)) | |
-#define SfShape_val(shp) ((sf::Shape *)(shp)) | |
+value Val_sfShape(sf::Shape * p); | |
+sf::Shape * SfShape_val(value v); | |
#define SfShape_val_u(shape) \ | |
SfShape_val(Field(shape,0)) | |
diff --git a/src/cxx_stubs/SFSocketSelector_stub.cpp b/src/cxx_stubs/SFSocketSelector_stub.cpp | |
index 1f5261a..d16c348 100644 | |
--- a/src/cxx_stubs/SFSocketSelector_stub.cpp | |
+++ b/src/cxx_stubs/SFSocketSelector_stub.cpp | |
@@ -30,8 +30,15 @@ | |
#include "SFUdpSocket_stub.hpp" | |
#include "SFTime_stub.hpp" | |
-#define SfSocketSelector_val(s) ((sf::SocketSelector *)(s)) | |
-#define Val_sfSocketSelector(s) ((value)(s)) | |
+static value Val_sfSocketSelector(sf::SocketSelector * p) | |
+{ | |
+ return caml_copy_nativeint((intnat) p); | |
+} | |
+ | |
+static sf::SocketSelector * SfSocketSelector_val(value v) | |
+{ | |
+ return (sf::SocketSelector *) Nativeint_val(v); | |
+} | |
CAMLextern_C value | |
caml_sfSocketSelector_create(value unit) | |
diff --git a/src/cxx_stubs/SFSoundBufferRecorder_stub.cpp b/src/cxx_stubs/SFSoundBufferRecorder_stub.cpp | |
index 225e10c..58a1d1d 100644 | |
--- a/src/cxx_stubs/SFSoundBufferRecorder_stub.cpp | |
+++ b/src/cxx_stubs/SFSoundBufferRecorder_stub.cpp | |
@@ -25,8 +25,14 @@ | |
#include "sf_caml_incs.hpp" | |
-#define Val_sfSoundBufferRecorder(sbr) ((value)(sbr)) | |
-#define SfSoundBufferRecorder_val(sbr) ((sf::SoundBufferRecorder *)(sbr)) | |
+static value Val_sfSoundBufferRecorder(sf::SoundBufferRecorder * p) | |
+{ | |
+ return caml_copy_nativeint((intnat) p); | |
+} | |
+static sf::SoundBufferRecorder * SfSoundBufferRecorder_val(value v) | |
+{ | |
+ return (sf::SoundBufferRecorder *) Nativeint_val(v); | |
+} | |
CAMLextern_C value | |
caml_sfSoundBufferRecorder_create() | |
diff --git a/src/cxx_stubs/SFSoundBuffer_stub.cpp b/src/cxx_stubs/SFSoundBuffer_stub.cpp | |
index cf860c4..e448846 100644 | |
--- a/src/cxx_stubs/SFSoundBuffer_stub.cpp | |
+++ b/src/cxx_stubs/SFSoundBuffer_stub.cpp | |
@@ -28,6 +28,16 @@ | |
#include "SFSoundBuffer_stub.hpp" | |
#include "SFTime_stub.hpp" | |
+value Val_sfSoundBuffer(sf::SoundBuffer * p) | |
+{ | |
+ return caml_copy_nativeint((intnat) p); | |
+} | |
+ | |
+sf::SoundBuffer * SfSoundBuffer_val(value v) | |
+{ | |
+ return (sf::SoundBuffer *) Nativeint_val(v); | |
+} | |
+ | |
/* sf::SoundBuffer */ | |
diff --git a/src/cxx_stubs/SFSoundBuffer_stub.hpp b/src/cxx_stubs/SFSoundBuffer_stub.hpp | |
index 6a00bd1..d462c36 100644 | |
--- a/src/cxx_stubs/SFSoundBuffer_stub.hpp | |
+++ b/src/cxx_stubs/SFSoundBuffer_stub.hpp | |
@@ -3,8 +3,8 @@ | |
#include <SFML/Audio/SoundBuffer.hpp> | |
-#define Val_sfSoundBuffer(sdb) ((value)(sdb)) | |
-#define SfSoundBuffer_val(sdb) ((sf::SoundBuffer *)(sdb)) | |
+value Val_sfSoundBuffer(sf::SoundBuffer * p); | |
+sf::SoundBuffer * SfSoundBuffer_val(value v); | |
#define SfSoundBuffer_val_u(sdb) SfSoundBuffer_val(Field(sdb,0)) | |
diff --git a/src/cxx_stubs/SFSound_stub.cpp b/src/cxx_stubs/SFSound_stub.cpp | |
index a4788df..270eb28 100644 | |
--- a/src/cxx_stubs/SFSound_stub.cpp | |
+++ b/src/cxx_stubs/SFSound_stub.cpp | |
@@ -28,8 +28,8 @@ | |
#include "SFTime_stub.hpp" | |
#include "SFSoundBuffer_stub.hpp" | |
-#define Val_sfSound(snd) ((value)(snd)) | |
-#define SfSound_val(snd) ((sf::Sound *)(snd)) | |
+static value Val_sfSound(sf::Sound * p) { return caml_copy_nativeint((intnat) p); } | |
+static sf::Sound * SfSound_val(value v) { return (sf::Sound *) Nativeint_val(v); } | |
static value | |
Val_sfSoundStatus(sf::Sound::Status sndst) | |
diff --git a/src/cxx_stubs/SFSprite_stub.cpp b/src/cxx_stubs/SFSprite_stub.cpp | |
index 5e5ece9..b28cf4a 100644 | |
--- a/src/cxx_stubs/SFSprite_stub.cpp | |
+++ b/src/cxx_stubs/SFSprite_stub.cpp | |
@@ -29,6 +29,16 @@ | |
#include "SFTexture_stub.hpp" | |
#include "SFColor_stub.hpp" | |
+value Val_sfSprite(sf::Sprite * p) | |
+{ | |
+ return caml_copy_nativeint((intnat) p); | |
+} | |
+ | |
+sf::Sprite * SfSprite_val(value v) | |
+{ | |
+ return (sf::Sprite *) Nativeint_val(v); | |
+} | |
+ | |
/* sf::Sprite */ | |
CAMLextern_C value | |
diff --git a/src/cxx_stubs/SFSprite_stub.hpp b/src/cxx_stubs/SFSprite_stub.hpp | |
index 2d426a5..000975f 100644 | |
--- a/src/cxx_stubs/SFSprite_stub.hpp | |
+++ b/src/cxx_stubs/SFSprite_stub.hpp | |
@@ -3,9 +3,8 @@ | |
#include <SFML/Graphics/Sprite.hpp> | |
- | |
-#define Val_sfSprite(spr) ((value)(spr)) | |
-#define SfSprite_val(spr) ((sf::Sprite *)(spr)) | |
+value Val_sfSprite(sf::Sprite * p); | |
+sf::Sprite * SfSprite_val(value v); | |
#define SfSprite_val_u(sprite) \ | |
SfSprite_val(Field(sprite,0)) | |
diff --git a/src/cxx_stubs/SFTcpListener_stub.cpp b/src/cxx_stubs/SFTcpListener_stub.cpp | |
index 384627f..df3ab5c 100644 | |
--- a/src/cxx_stubs/SFTcpListener_stub.cpp | |
+++ b/src/cxx_stubs/SFTcpListener_stub.cpp | |
@@ -31,6 +31,17 @@ | |
#include "SFSocket_stub.hpp" | |
+value Val_sfTcpListener(sf::TcpListener * p) | |
+{ | |
+ return caml_copy_nativeint((intnat) p); | |
+} | |
+ | |
+sf::TcpListener * SfTcpListener_val(value v) | |
+{ | |
+ return (sf::TcpListener *) Nativeint_val(v); | |
+} | |
+ | |
+ | |
CAMLextern_C value | |
caml_sfTcpListener_create(value unit) | |
{ | |
diff --git a/src/cxx_stubs/SFTcpListener_stub.hpp b/src/cxx_stubs/SFTcpListener_stub.hpp | |
index b5c8ad3..bfbb5c6 100644 | |
--- a/src/cxx_stubs/SFTcpListener_stub.hpp | |
+++ b/src/cxx_stubs/SFTcpListener_stub.hpp | |
@@ -3,7 +3,7 @@ | |
#include <SFML/Network/TcpListener.hpp> | |
-#define Val_sfTcpListener(list) ((value)(list)) | |
-#define SfTcpListener_val(list) ((sf::TcpListener *)(list)) | |
+value Val_sfTcpListener(sf::TcpListener * p); | |
+sf::TcpListener * SfTcpListener_val(value v); | |
#endif // _SF_TCPLISTENER_INC | |
diff --git a/src/cxx_stubs/SFTcpSocket_stub.cpp b/src/cxx_stubs/SFTcpSocket_stub.cpp | |
index 6dc65dd..18d87a1 100644 | |
--- a/src/cxx_stubs/SFTcpSocket_stub.cpp | |
+++ b/src/cxx_stubs/SFTcpSocket_stub.cpp | |
@@ -32,6 +32,17 @@ | |
#include "SFTime_stub.hpp" | |
+value Val_sfTcpSocket(sf::TcpSocket * p) | |
+{ | |
+ return caml_copy_nativeint((intnat) p); | |
+} | |
+ | |
+sf::TcpSocket * SfTcpSocket_val(value v) | |
+{ | |
+ return (sf::TcpSocket *) Nativeint_val(v); | |
+} | |
+ | |
+ | |
/* sf::TcpSocket */ | |
CAMLextern_C value | |
diff --git a/src/cxx_stubs/SFTcpSocket_stub.hpp b/src/cxx_stubs/SFTcpSocket_stub.hpp | |
index ca3e66c..9f6793e 100644 | |
--- a/src/cxx_stubs/SFTcpSocket_stub.hpp | |
+++ b/src/cxx_stubs/SFTcpSocket_stub.hpp | |
@@ -3,7 +3,7 @@ | |
#include <SFML/Network/TcpSocket.hpp> | |
-#define Val_sfTcpSocket(sock) ((value)(sock)) | |
-#define SfTcpSocket_val(sock) ((sf::TcpSocket *)(sock)) | |
+value Val_sfTcpSocket(sf::TcpSocket * p); | |
+sf::TcpSocket * SfTcpSocket_val(value v); | |
#endif // _SF_TCPSOCKET_INC | |
diff --git a/src/cxx_stubs/SFText_stub.cpp b/src/cxx_stubs/SFText_stub.cpp | |
index fda0561..0ecb80e 100644 | |
--- a/src/cxx_stubs/SFText_stub.cpp | |
+++ b/src/cxx_stubs/SFText_stub.cpp | |
@@ -30,6 +30,16 @@ | |
#include "SFRect_stub.hpp" | |
#include "SFFont_stub.hpp" | |
+value Val_sfText(sf::Text * p) | |
+{ | |
+ return caml_copy_nativeint((intnat) p); | |
+} | |
+ | |
+sf::Text * SfText_val(value v) | |
+{ | |
+ return (sf::Text *) Nativeint_val(v); | |
+} | |
+ | |
/* sf::Text */ | |
diff --git a/src/cxx_stubs/SFText_stub.hpp b/src/cxx_stubs/SFText_stub.hpp | |
index 4103f36..fdd15b6 100644 | |
--- a/src/cxx_stubs/SFText_stub.hpp | |
+++ b/src/cxx_stubs/SFText_stub.hpp | |
@@ -4,8 +4,8 @@ | |
#include <SFML/Graphics/Text.hpp> | |
-#define Val_sfText(txt) ((value)(txt)) | |
-#define SfText_val(txt) ((sf::Text *)(txt)) | |
+value Val_sfText(sf::Text * p); | |
+sf::Text * SfText_val(value v); | |
#define SfText_val_u(text) \ | |
SfText_val(Field(text,0)) | |
diff --git a/src/cxx_stubs/SFTexture_stub.cpp b/src/cxx_stubs/SFTexture_stub.cpp | |
index 7c5bb71..ea5e42c 100644 | |
--- a/src/cxx_stubs/SFTexture_stub.cpp | |
+++ b/src/cxx_stubs/SFTexture_stub.cpp | |
@@ -30,6 +30,16 @@ | |
#include "SFRect_stub.hpp" | |
#include "SFImage_stub.hpp" | |
+value Val_sfTexture(sf::Texture * p) | |
+{ | |
+ return caml_copy_nativeint((intnat) p); | |
+} | |
+ | |
+sf::Texture * SfTexture_val(value v) | |
+{ | |
+ return (sf::Texture *) Nativeint_val(v); | |
+} | |
+ | |
/* sf::Texture */ | |
CAMLextern_C value | |
diff --git a/src/cxx_stubs/SFTexture_stub.hpp b/src/cxx_stubs/SFTexture_stub.hpp | |
index 09e3274..38ad1bd 100644 | |
--- a/src/cxx_stubs/SFTexture_stub.hpp | |
+++ b/src/cxx_stubs/SFTexture_stub.hpp | |
@@ -3,8 +3,7 @@ | |
#include <SFML/Graphics/Texture.hpp> | |
- | |
-#define Val_sfTexture(tex) ((value)(tex)) | |
-#define SfTexture_val(tex) ((sf::Texture *)(tex)) | |
+value Val_sfTexture(sf::Texture * p); | |
+sf::Texture * SfTexture_val(value v); | |
#endif // _SF_TEXTURE_INC | |
diff --git a/src/cxx_stubs/SFUdpSocket_stub.cpp b/src/cxx_stubs/SFUdpSocket_stub.cpp | |
index a877b09..b831210 100644 | |
--- a/src/cxx_stubs/SFUdpSocket_stub.cpp | |
+++ b/src/cxx_stubs/SFUdpSocket_stub.cpp | |
@@ -30,6 +30,16 @@ | |
#include "SFIpAddress_stub.hpp" | |
#include "SFPacket_stub.hpp" | |
+value Val_sfUdpSocket(sf::UdpSocket * p) | |
+{ | |
+ return caml_copy_nativeint((intnat) p); | |
+} | |
+ | |
+sf::UdpSocket * SfUdpSocket_val(value v) | |
+{ | |
+ return (sf::UdpSocket *) Nativeint_val(v); | |
+} | |
+ | |
CAMLextern_C value | |
caml_sfUdpSocket_create(value unit) | |
diff --git a/src/cxx_stubs/SFUdpSocket_stub.hpp b/src/cxx_stubs/SFUdpSocket_stub.hpp | |
index 167caef..5bb139d 100644 | |
--- a/src/cxx_stubs/SFUdpSocket_stub.hpp | |
+++ b/src/cxx_stubs/SFUdpSocket_stub.hpp | |
@@ -3,7 +3,7 @@ | |
#include <SFML/Network/UdpSocket.hpp> | |
-#define Val_sfUdpSocket(sck) ((value)(sck)) | |
-#define SfUdpSocket_val(sck) ((sf::UdpSocket *)(sck)) | |
+value Val_sfUdpSocket(sf::UdpSocket * p); | |
+sf::UdpSocket * SfUdpSocket_val(value v); | |
#endif // _SF_UDPSOCKET_INC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment