diff --git a/try/c/data_types.c b/try/c/data_types.c index a771152..13dd923 100644 --- a/try/c/data_types.c +++ b/try/c/data_types.c @@ -1,49 +1,41 @@ +/* +------------------------------- +Difficult Rocket +Copyright © 2021-2022 by shenjackyuanjie +All rights reserved +------------------------------- +*/ // DR数据类型 -#include -#include "data_utils.h" // 自己搓的一个常用数据类型的头文件 +#include"Python.h" +#include +#include"data_utils.h" // 自己搓的一个常用数据类型的头文件 -struct ship_part +struct ship_part // 一个部件的基本数据类型 { /* 一个 part 的数据格式 */ string part_type; int32 part_id; - bool enabled; float64 x; float64 v_x; float64 y; float64 v_y; - float32 angle; + float64 angle; float64 v_angle; + // TODO 会改成基于 float 64的数组 bool flip_x; bool flip_y; -} ship_part = { + bool part_enabled; + // TODO 也改成数组 +} a_ship_part = { "pod", 0, - false, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - false, - false + 0, 0, 0, 0, 0, 0, + false, false, false }; +struct ship_part a_part; +// a_part = {}; + int main(){ - // 创建一个 part - struct ship_part p; - p.part_type = "head"; - p.part_id = 1; - p.enabled = true; - - // 创建一个 part 的数组 - struct ship_part *parts = malloc(sizeof(struct ship_part) * 10); - - // 输出一个 part 的数据 - printf("%s %d %d %f %f %f %f %f %f %d %d\n", - p.part_type, p.part_id, p.enabled, - p.x, p.v_x, p.y, p.v_y, p.angle, p.v_angle, - p.flip_x, p.flip_y); - return 0; -} +} \ No newline at end of file diff --git a/try/c/data_types.dll b/try/c/data_types.dll index 01ffb58..c30b22d 100644 Binary files a/try/c/data_types.dll and b/try/c/data_types.dll differ diff --git a/try/c/data_types.so b/try/c/data_types.so deleted file mode 100755 index 3a3f2ae..0000000 Binary files a/try/c/data_types.so and /dev/null differ diff --git a/try/c/data_utils.h b/try/c/data_utils.h index 49a315f..68038ca 100644 --- a/try/c/data_utils.h +++ b/try/c/data_utils.h @@ -1,4 +1,10 @@ -/* by shenjackyuanjie 一些数据类型的转换 */ +/* 一个好用的头文件 +------------------------------- +Difficult Rocket +Copyright © 2021-2022 by shenjackyuanjie +All rights reserved +------------------------------- +*/ // 基本的头文件引用 #include @@ -21,7 +27,7 @@ #define float32 float #define float64 double // bool 布尔值 -#define bool int8 +#define bool int #define true 1 #define false 0 // 字符串 diff --git a/try/c/dll_build.ps1 b/try/c/dll_build.ps1 deleted file mode 100644 index b062acb..0000000 --- a/try/c/dll_build.ps1 +++ /dev/null @@ -1 +0,0 @@ -gcc -shared -o \ No newline at end of file diff --git a/try/c/dll_builder.py b/try/c/dll_builder.py new file mode 100644 index 0000000..6c97f88 --- /dev/null +++ b/try/c/dll_builder.py @@ -0,0 +1,21 @@ +# ------------------------------- +# Difficult Rocket +# Copyright © 2021-2022 by shenjackyuanjie +# All rights reserved +# ------------------------------- + +import os +import sys +import getopt + + +# input_args = sys.argv + +# print(input_args) +filename = "./data_types.c" +dllname = "./data_types.dll" + +python_include_path = "C:/Users/shenjack.SHENJACK-5600X/AppData/Local/Programs/Python/Python38/include/" + +os.system("gcc -I {} -shared {} -o {}".format(python_include_path, filename, dllname)) +# gcc -I C:/Users/shenjack.SHENJACK-5600X/AppData/Local/Programs/Python/Python38/include/ -shared .\data_types.c -o .\data_types.dll \ No newline at end of file diff --git a/try/c/dll_load.py b/try/c/dll_load.py index bcd9b3b..dd6c89c 100644 --- a/try/c/dll_load.py +++ b/try/c/dll_load.py @@ -6,4 +6,14 @@ import ctypes -ctypes.CDLL('./data_types.dll') \ No newline at end of file +ctypes.cdll.LoadLibrary('./data_types.dll') + +data_type_dll = ctypes.CDLL("./data_types.dll") + +print(data_type_dll) + +a = data_type_dll.a_part + +print(a) + +print(a.part_type)