Simplify handling of exported functions
parent
f70ee909f2
commit
a0f5af1f4a
|
@ -1,11 +1,18 @@
|
|||
From 6c0fa674b91057fe27da23802c969adcb8f55385 Mon Sep 17 00:00:00 2001
|
||||
From: Pierre-Yves Rollo <dev@pyrollo.com>
|
||||
Date: Tue, 25 Jun 2019 10:59:30 +0200
|
||||
From 1ea38575248fdf0467a8a57a9a43301e33592024 Mon Sep 17 00:00:00 2001
|
||||
From: Pedro Gimeno <pgimeno@users.noreply.notabug.org>
|
||||
Date: Tue, 25 Jun 2019 13:36:22 +0200
|
||||
Subject: [PATCH] Add FFI pointer and size retrieval and sanity check functions
|
||||
|
||||
---
|
||||
src/mapnode.cpp | 9 +++++++++
|
||||
src/porting.h | 2 ++
|
||||
src/script/lua_api/l_noise.cpp | 44 +++++++++++++++++++++++++++++++++++++++++
|
||||
src/script/lua_api/l_noise.h | 2 ++
|
||||
src/script/lua_api/l_vmanip.cpp | 20 +++++++++++++++++++
|
||||
5 files changed, 77 insertions(+)
|
||||
|
||||
diff --git a/src/mapnode.cpp b/src/mapnode.cpp
|
||||
index 9761a661..41a7e71b 100644
|
||||
index 9761a661..b6840eb1 100644
|
||||
--- a/src/mapnode.cpp
|
||||
+++ b/src/mapnode.cpp
|
||||
@@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
|
@ -16,30 +23,43 @@ index 9761a661..41a7e71b 100644
|
|||
|
||||
static const Rotation wallmounted_to_rot[] = {
|
||||
ROTATE_0, ROTATE_180, ROTATE_90, ROTATE_270
|
||||
@@ -44,6 +45,21 @@ static const u8 rot_to_wallmounted[] = {
|
||||
@@ -44,6 +45,14 @@ static const u8 rot_to_wallmounted[] = {
|
||||
MapNode
|
||||
*/
|
||||
|
||||
+extern "C" {
|
||||
+
|
||||
+#ifdef WIN32
|
||||
+__declspec(dllexport)
|
||||
+#endif
|
||||
+int get_mapnode_version(void)
|
||||
+extern "C" EXPORT int get_mapnode_version(void)
|
||||
+{
|
||||
+ if (sizeof(MapNode) == 4 && offsetof(MapNode, param0) == 0
|
||||
+ && offsetof(MapNode, param1) == 2 && offsetof(MapNode, param2) == 3)
|
||||
+ return 1;
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+} // extern "C"
|
||||
+
|
||||
void MapNode::getColor(const ContentFeatures &f, video::SColor *color) const
|
||||
{
|
||||
if (f.palette) {
|
||||
diff --git a/src/porting.h b/src/porting.h
|
||||
index 4d30a597..56419ff9 100644
|
||||
--- a/src/porting.h
|
||||
+++ b/src/porting.h
|
||||
@@ -54,6 +54,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include <windows.h>
|
||||
|
||||
#define sleep_ms(x) Sleep(x)
|
||||
+ #define EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <cstdint> //for uintptr_t
|
||||
@@ -67,6 +68,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#endif
|
||||
|
||||
#define sleep_ms(x) usleep(x*1000)
|
||||
+ #define EXPORT
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
diff --git a/src/script/lua_api/l_noise.cpp b/src/script/lua_api/l_noise.cpp
|
||||
index e38d319f..11363e39 100644
|
||||
index e38d319f..47955977 100644
|
||||
--- a/src/script/lua_api/l_noise.cpp
|
||||
+++ b/src/script/lua_api/l_noise.cpp
|
||||
@@ -17,6 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
|
@ -50,16 +70,13 @@ index e38d319f..11363e39 100644
|
|||
#include "lua_api/l_noise.h"
|
||||
#include "lua_api/l_internal.h"
|
||||
#include "common/c_converter.h"
|
||||
@@ -401,6 +402,58 @@ luaL_Reg LuaPerlinNoiseMap::methods[] = {
|
||||
@@ -401,6 +402,49 @@ luaL_Reg LuaPerlinNoiseMap::methods[] = {
|
||||
{0,0}
|
||||
};
|
||||
|
||||
+extern "C" {
|
||||
+
|
||||
+#ifdef WIN32
|
||||
+__declspec(dllexport)
|
||||
+#endif
|
||||
+size_t PerlinNoiseMap_get_area(void **pnmp)
|
||||
+EXPORT size_t PerlinNoiseMap_get_area(void **pnmp)
|
||||
+{
|
||||
+ NO_MAP_LOCK_REQUIRED;
|
||||
+
|
||||
|
@ -73,10 +90,7 @@ index e38d319f..11363e39 100644
|
|||
+ return n->sx * n->sy;
|
||||
+}
|
||||
+
|
||||
+#ifdef WIN32
|
||||
+__declspec(dllexport)
|
||||
+#endif
|
||||
+size_t PerlinNoiseMap_get_volume(void **pnmp)
|
||||
+EXPORT size_t PerlinNoiseMap_get_volume(void **pnmp)
|
||||
+{
|
||||
+ NO_MAP_LOCK_REQUIRED;
|
||||
+
|
||||
|
@ -90,10 +104,7 @@ index e38d319f..11363e39 100644
|
|||
+ return n->sx * n->sy * n->sz;
|
||||
+}
|
||||
+
|
||||
+#ifdef WIN32
|
||||
+__declspec(dllexport)
|
||||
+#endif
|
||||
+void PerlinNoiseMap_get_pointer(void **pnmp, void **ptr)
|
||||
+EXPORT void PerlinNoiseMap_get_pointer(void **pnmp, void **ptr)
|
||||
+{
|
||||
+ NO_MAP_LOCK_REQUIRED;
|
||||
+
|
||||
|
@ -123,19 +134,16 @@ index 9f50dfd3..49a7ec6e 100644
|
|||
|
||||
/*
|
||||
diff --git a/src/script/lua_api/l_vmanip.cpp b/src/script/lua_api/l_vmanip.cpp
|
||||
index c92983bd..574883fa 100644
|
||||
index c92983bd..8401657d 100644
|
||||
--- a/src/script/lua_api/l_vmanip.cpp
|
||||
+++ b/src/script/lua_api/l_vmanip.cpp
|
||||
@@ -30,6 +30,32 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
@@ -30,6 +30,26 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include "mapgen/mapgen.h"
|
||||
#include "voxelalgorithms.h"
|
||||
|
||||
+extern "C" {
|
||||
+
|
||||
+#ifdef WIN32
|
||||
+__declspec(dllexport)
|
||||
+#endif
|
||||
+void VoxelManip_get_pointer(void **lvmp, void **ptr)
|
||||
+EXPORT void VoxelManip_get_pointer(void **lvmp, void **ptr)
|
||||
+{
|
||||
+ if (lvmp == nullptr || ptr == nullptr)
|
||||
+ throw ModError("Nil pointer in C call");
|
||||
|
@ -143,10 +151,7 @@ index c92983bd..574883fa 100644
|
|||
+ *ptr = (*(LuaVoxelManip **)lvmp)->vm->m_data;
|
||||
+}
|
||||
+
|
||||
+#ifdef WIN32
|
||||
+__declspec(dllexport)
|
||||
+#endif
|
||||
+s32 VoxelManip_get_volume(void **lvmp)
|
||||
+EXPORT s32 VoxelManip_get_volume(void **lvmp)
|
||||
+{
|
||||
+ if (lvmp == nullptr)
|
||||
+ throw ModError("Nil pointer in C call");
|
||||
|
@ -160,5 +165,5 @@ index c92983bd..574883fa 100644
|
|||
int LuaVoxelManip::gc_object(lua_State *L)
|
||||
{
|
||||
--
|
||||
2.20.1
|
||||
2.11.0
|
||||
|
||||
|
|
Loading…
Reference in New Issue