Skip to content

Commit

Permalink
add binding for python
Browse files Browse the repository at this point in the history
  • Loading branch information
tmori committed Feb 4, 2024
1 parent d3fad51 commit d015d9a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
20 changes: 20 additions & 0 deletions bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.12)
project(hakoniwa_multi_language_project)

find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})
set(CMAKE_SWIG_FLAGS "")

# ヘッダーファイルのインクルードパスを設定
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src/include)
# SWIGインターフェースファイルの相対パスを設定
set(SWIG_INTERFACE_FILE ${CMAKE_CURRENT_SOURCE_DIR}/hako_asset.i)
set_source_files_properties(${SWIG_INTERFACE_FILE} PROPERTIES CPLUSPLUS ON)
# ライブラリのフルパスを検索
find_library(ASSETS_LIBRARY
NAMES assets
PATHS /usr/local/lib/hakoniwa
)

add_subdirectory(python)

Empty file added bindings/cmake-build/.gitkeep
Empty file.
26 changes: 26 additions & 0 deletions bindings/hako_asset.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
%module hako_asset

%{
#include "hako_asset.h"
%}

%include "hako_primitive_types.h"


%typemap(in) hako_asset_callbacks_t *callbacks (void *ptr) {
$1 = (hako_asset_callbacks_t *)malloc(sizeof(hako_asset_callbacks_t));
if (!$1) {
PyErr_NoMemory();
return NULL;
}
$1->on_initialize = NULL;
$1->on_simulation_step = NULL;
$1->on_manual_timing_control = NULL;
$1->on_reset = NULL;
ptr = $1;
}

%typemap(freearg) hako_asset_callbacks_t *callbacks {
free($1);
}
%include "hako_asset.h"
8 changes: 8 additions & 0 deletions bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.12)
project(hakoniwa_python_swig_project)

find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_PATH})

swig_add_library(hako_asset_py LANGUAGE python SOURCES ${SWIG_INTERFACE_FILE})
swig_link_libraries(hako_asset_py ${PYTHON_LIBRARIES} ${ASSETS_LIBRARY})

0 comments on commit d015d9a

Please sign in to comment.