This commit is contained in:
shenjackyuanjie 2022-05-03 13:59:15 +08:00
parent cfc6ff569e
commit baa00a3b0c
7 changed files with 62 additions and 34 deletions

View File

@ -1,49 +1,41 @@
/*
-------------------------------
Difficult Rocket
Copyright © 2021-2022 by shenjackyuanjie
All rights reserved
-------------------------------
*/
// DR数据类型 // DR数据类型
#include"Python.h"
#include<stdlib.h> #include<stdlib.h>
#include"data_utils.h" // 自己搓的一个常用数据类型的头文件 #include"data_utils.h" // 自己搓的一个常用数据类型的头文件
struct ship_part struct ship_part // 一个部件的基本数据类型
{ {
/* 一个 part 的数据格式 */ /* 一个 part 的数据格式 */
string part_type; string part_type;
int32 part_id; int32 part_id;
bool enabled;
float64 x; float64 x;
float64 v_x; float64 v_x;
float64 y; float64 y;
float64 v_y; float64 v_y;
float32 angle; float64 angle;
float64 v_angle; float64 v_angle;
// TODO 会改成基于 float 64的数组
bool flip_x; bool flip_x;
bool flip_y; bool flip_y;
} ship_part = { bool part_enabled;
// TODO 也改成数组
} a_ship_part = {
"pod", "pod",
0, 0,
false, 0, 0, 0, 0, 0, 0,
0.0, false, false, false
0.0,
0.0,
0.0,
0.0,
false,
false
}; };
struct ship_part a_part;
// a_part = {};
int main(){ 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; return 0;
} }

Binary file not shown.

Binary file not shown.

View File

@ -1,4 +1,10 @@
/* by shenjackyuanjie 一些数据类型的转换 */ /* 一个好用的头文件
-------------------------------
Difficult Rocket
Copyright © 2021-2022 by shenjackyuanjie
All rights reserved
-------------------------------
*/
// 基本的头文件引用 // 基本的头文件引用
#include<stdio.h> #include<stdio.h>
@ -21,7 +27,7 @@
#define float32 float #define float32 float
#define float64 double #define float64 double
// bool 布尔值 // bool 布尔值
#define bool int8 #define bool int
#define true 1 #define true 1
#define false 0 #define false 0
// 字符串 // 字符串

View File

@ -1 +0,0 @@
gcc -shared -o

21
try/c/dll_builder.py Normal file
View File

@ -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

View File

@ -6,4 +6,14 @@
import ctypes import ctypes
ctypes.CDLL('./data_types.dll') 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)