mirror of
https://github.com/Gongxh0901/kunpolibrary
synced 2025-10-29 10:25:48 +00:00
仓库中添加内置的demo
This commit is contained in:
95
demo/tools/swig-config/SDKHelper.i
Normal file
95
demo/tools/swig-config/SDKHelper.i
Normal file
@@ -0,0 +1,95 @@
|
||||
// Define module
|
||||
// target_namespace means the name exported to JS, could be same as which in other modules
|
||||
// assets at the last means the suffix of binding function name, different modules should use unique name
|
||||
// Note: doesn't support number prefix
|
||||
%module(target_namespace="KunpoSDK") SDKHelper
|
||||
|
||||
// Disable some swig warnings, find warning number reference here ( https://www.swig.org/Doc4.1/Warnings.html )
|
||||
// #pragma SWIG nowarn=503,302,401,317,402
|
||||
|
||||
// %insert(header_file) %{ ... }%} 代码块中的内容最终会被原封不动地插入到生成的头文件(.h)开头的地方
|
||||
%insert(header_file) %{
|
||||
#pragma once
|
||||
#include "bindings/jswrapper/SeApi.h"
|
||||
#include "bindings/manual/jsb_conversions.h"
|
||||
#include "cocos/cocos.h"
|
||||
|
||||
#include "../../SDKHelper.h" // 添加这行,%include 指令表示让 swig 解析此文件,并且为此文件中的类生成绑定代码。
|
||||
%}
|
||||
|
||||
// %{ ... %} 代码块中的内容最终会被原封不动地插入到生成的源文件(.cpp)开头的地方
|
||||
%{
|
||||
#include "jsb_SDKHelper_auto.h"
|
||||
%}
|
||||
|
||||
|
||||
%include "SDKHelper.h"
|
||||
// ----- 忽略的部分 ------
|
||||
// Brief: 类、方法或属性需要被忽略
|
||||
//
|
||||
// Usage:
|
||||
//
|
||||
// %ignore your_namespace::your_class_name;
|
||||
// %ignore your_namespace::your_class_name::your_method_name;
|
||||
// %ignore your_namespace::your_class_name::your_attribute_name;
|
||||
//
|
||||
// Note:
|
||||
// 1. 'Ignore Section' should be placed before attribute definition and %import/%include
|
||||
// 2. namespace is needed
|
||||
//
|
||||
|
||||
|
||||
// ----- 重命名部分 ------
|
||||
// Brief: 类、方法或属性需要被重命名
|
||||
//
|
||||
// Usage:
|
||||
//
|
||||
// %rename(rename_to_name) your_namespace::original_class_name;
|
||||
// %rename(rename_to_name) your_namespace::original_class_name::method_name;
|
||||
// %rename(rename_to_name) your_namespace::original_class_name::attribute_name;
|
||||
//
|
||||
// Note:
|
||||
// 1. 'Rename Section' should be placed before attribute definition and %import/%include
|
||||
// 2. namespace is needed
|
||||
|
||||
|
||||
|
||||
// ----- Module Macro Section ------
|
||||
// Brief: Generated code should be wrapped inside a macro
|
||||
// Usage:
|
||||
// 1. Configure for class
|
||||
// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::GeometryRenderer;
|
||||
// 2. Configure for member function or attribute
|
||||
// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::RenderPipeline::geometryRenderer;
|
||||
// Note: Should be placed before 'Attribute Section'
|
||||
|
||||
// Write your code bellow
|
||||
|
||||
|
||||
// ----- Attribute Section ------
|
||||
// Brief: Define attributes ( JS properties with getter and setter )
|
||||
// Usage:
|
||||
// 1. Define an attribute without setter
|
||||
// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name)
|
||||
// 2. Define an attribute with getter and setter
|
||||
// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name, cpp_setter_name)
|
||||
// 3. Define an attribute without getter
|
||||
// %attribute_writeonly(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_setter_name)
|
||||
//
|
||||
// Note:
|
||||
// 1. Don't need to add 'const' prefix for cpp_member_variable_type
|
||||
// 2. The return type of getter should keep the same as the type of setter's parameter
|
||||
// 3. If using reference, add '&' suffix for cpp_member_variable_type to avoid generated code using value assignment
|
||||
// 4. 'Attribute Section' should be placed before 'Import Section' and 'Include Section'
|
||||
//
|
||||
|
||||
|
||||
// ----- Import Section ------
|
||||
// Brief: Import header files which are depended by 'Include Section'
|
||||
// Note:
|
||||
// %import "your_header_file.h" will not generate code for that header file
|
||||
//
|
||||
|
||||
|
||||
// ----- Include Section ------
|
||||
// Brief: Include header files in which classes and methods will be bound
|
||||
37
demo/tools/swig-config/swig-config.js
Normal file
37
demo/tools/swig-config/swig-config.js
Normal file
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* @Author: Gongxh
|
||||
* @Date: 2025-03-21
|
||||
* @Description:
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
const path = require('path');
|
||||
|
||||
// 开发者自己的模块定义配置
|
||||
// configList 是必须的
|
||||
const configList = [
|
||||
[ 'SDKHelper.i', 'jsb_SDKHelper_auto.cpp' ],
|
||||
];
|
||||
|
||||
const projectRoot = path.resolve(path.join(__dirname, '..', '..'));
|
||||
// interfaceDir 是可选的
|
||||
const interfacesDir = path.join(projectRoot, 'tools', 'swig-config');
|
||||
// bindingsOutDir 是可选的
|
||||
const bindingsOutDir = path.join(projectRoot, 'native', 'engine', 'common', 'Classes', 'bindings', 'auto');
|
||||
|
||||
// includeDirs 意思是 swig 执行时候使用的头文件搜索路径
|
||||
const includeDirs = [
|
||||
path.join(projectRoot, 'native', 'engine', 'common', 'Classes'),
|
||||
];
|
||||
|
||||
module.exports = {
|
||||
interfacesDir, // 可选参数, 如果没有指定,configList 中的路径必须为绝对路径或者相对于当前 swig-config.js 的相对路径
|
||||
bindingsOutDir, // 可选参数,如果没有指定, configList 中的路径必须为绝对路径或者相对于当前 swig-config.js 的相对路径
|
||||
includeDirs,
|
||||
configList // 必填参数
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// # 如果当前终端或者命令提示符所在的目录不是在 '/Users/abc/my-project/tools/swig-config'
|
||||
// node /Applications/Cocos/Creator/3.8.0/CocosCreator.app/Contents/Resources/resources/3d/engine/native/tools/swig-config/genbindings.js -c /Users/abc/my-project/tools/swig-config/swig-config.js
|
||||
Reference in New Issue
Block a user