开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 0

electron/ChaiScript

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
develop
分支 (15)
标签 (61)
develop
update-catch
gitignore-build
release-6.x
master
best_practices
test_limits
attempt_converting_unique_ptr_through_base_class
release-5.x
attempt_global_object_caching
typed_reworks
attempt_register_function_simplification
Workaround_Thread_Local_MinGW
value_types
release-4.x
v6.1.0
v6.0.0
v5.8.6
v5.8.5
v5.8.4
v5.8.3
v5.8.2
v5.8.1
v5.8.0
Test_Release
v5.7.1
v5.7.0
v5.6.0
v5.5.1
v5.5.0
v5.4.0
v5.3.1
v4.3.1
Release-5.3.0
Release-4.3.0
develop
分支 (15)
标签 (61)
develop
update-catch
gitignore-build
release-6.x
master
best_practices
test_limits
attempt_converting_unique_ptr_through_base_class
release-5.x
attempt_global_object_caching
typed_reworks
attempt_register_function_simplification
Workaround_Thread_Local_MinGW
value_types
release-4.x
v6.1.0
v6.0.0
v5.8.6
v5.8.5
v5.8.4
v5.8.3
v5.8.2
v5.8.1
v5.8.0
Test_Release
v5.7.1
v5.7.0
v5.6.0
v5.5.1
v5.5.0
v5.4.0
v5.3.1
v4.3.1
Release-5.3.0
Release-4.3.0
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
develop
分支 (15)
标签 (61)
develop
update-catch
gitignore-build
release-6.x
master
best_practices
test_limits
attempt_converting_unique_ptr_through_base_class
release-5.x
attempt_global_object_caching
typed_reworks
attempt_register_function_simplification
Workaround_Thread_Local_MinGW
value_types
release-4.x
v6.1.0
v6.0.0
v5.8.6
v5.8.5
v5.8.4
v5.8.3
v5.8.2
v5.8.1
v5.8.0
Test_Release
v5.7.1
v5.7.0
v5.6.0
v5.5.1
v5.5.0
v5.4.0
v5.3.1
v4.3.1
Release-5.3.0
Release-4.3.0
ChaiScript
/
src
/
test_module.cpp
ChaiScript
/
src
/
test_module.cpp
test_module.cpp 6.25 KB
一键复制 编辑 原始数据 按行查看 历史
Clemens Terasa 提交于 2025年02月20日 02:33 +08:00 . test_module: Fix noexcept warning
#include <chaiscript/chaiscript_basic.hpp>
#include <chaiscript/dispatchkit/bootstrap.hpp>
#include <string>
class TestBaseType {
public:
TestBaseType() noexcept
: val(10)
, const_val(15)
, mdarray{} {
}
TestBaseType(int) noexcept
: val(10)
, const_val(15)
, mdarray{} {
}
TestBaseType(int *) noexcept
: val(10)
, const_val(15)
, mdarray{} {
}
TestBaseType(const TestBaseType &other) noexcept
: val(other.val)
, const_val(other.const_val)
, const_val_ptr(&const_val)
, func_member(other.func_member) {
}
TestBaseType(TestBaseType &&other) noexcept
: val(other.val)
, const_val(other.const_val)
, const_val_ptr(&const_val)
, func_member(std::move(other.func_member)) {
}
TestBaseType &operator=(TestBaseType &&) = delete;
TestBaseType &operator=(const TestBaseType &) = delete;
virtual ~TestBaseType() = default;
virtual int func() { return 0; }
int base_only_func() { return -9; }
const TestBaseType &constMe() const { return *this; }
int val;
const int const_val;
const int *const_val_ptr = &const_val;
const int *get_const_val_ptr() { return const_val_ptr; }
int mdarray[2][3][5];
std::function<int(int)> func_member;
void set_string_val(std::string &t_str) { t_str = "42"; }
};
class Type2 {
public:
Type2(TestBaseType t_bt) noexcept
: m_bt(std::move(t_bt))
, m_str("Hello World") {
}
int get_val() const { return m_bt.val; }
const char *get_str() const { return m_str.c_str(); }
private:
TestBaseType m_bt;
std::string m_str;
};
enum TestEnum {
TestValue1 = 1
};
int to_int(TestEnum t) {
return t;
}
class TestDerivedType : public TestBaseType {
public:
int func() override { return 1; }
int derived_only_func() { return 19; }
};
class TestMoreDerivedType : public TestDerivedType {
public:
};
std::shared_ptr<TestBaseType> derived_type_factory() {
return std::make_shared<TestDerivedType>();
}
std::shared_ptr<TestBaseType> more_derived_type_factory() {
return std::make_shared<TestMoreDerivedType>();
}
std::shared_ptr<TestBaseType> null_factory() {
return std::shared_ptr<TestBaseType>();
}
void update_shared_ptr(std::shared_ptr<TestBaseType> &ptr) {
ptr = std::make_shared<TestDerivedType>();
}
void nullify_shared_ptr(std::shared_ptr<TestBaseType> &ptr) {
ptr = nullptr;
}
std::string hello_world() {
return "Hello World";
}
static int global_i = 1;
int *get_new_int() {
return &global_i;
}
// MSVC doesn't like that we are using C++ return types from our C declared module
// but this is the best way to do it for cross platform compatibility
#ifdef CHAISCRIPT_MSVC
#pragma warning(push)
#pragma warning(disable : 4190)
#endif
#ifdef __llvm__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wreturn-type-c-linkage"
#endif
CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_test_module() {
chaiscript::ModulePtr m(new chaiscript::Module());
m->add(chaiscript::fun(hello_world), "hello_world");
m->add(chaiscript::user_type<TestBaseType>(), "TestBaseType");
m->add(chaiscript::user_type<TestDerivedType>(), "TestDerivedType");
m->add(chaiscript::user_type<TestMoreDerivedType>(), "TestMoreDerivedType");
m->add(chaiscript::user_type<Type2>(), "Type2");
m->add(chaiscript::constructor<TestBaseType()>(), "TestBaseType");
// m->add(chaiscript::constructor<TestBaseType (int)>(), "TestBaseType");
m->add(chaiscript::constructor<TestBaseType(const TestBaseType &)>(), "TestBaseType");
m->add(chaiscript::constructor<TestBaseType(int *)>(), "TestBaseType");
m->add(chaiscript::constructor<TestDerivedType()>(), "TestDerivedType");
m->add(chaiscript::constructor<TestDerivedType(const TestDerivedType &)>(), "TestDerivedType");
m->add(chaiscript::constructor<TestMoreDerivedType()>(), "TestMoreDerivedType");
m->add(chaiscript::constructor<TestMoreDerivedType(const TestMoreDerivedType &)>(), "TestMoreDerivedType");
/// \todo automatic chaining of base classes?
m->add(chaiscript::base_class<TestBaseType, TestDerivedType>());
m->add(chaiscript::base_class<TestBaseType, TestMoreDerivedType>());
m->add(chaiscript::base_class<TestDerivedType, TestMoreDerivedType>());
m->add(chaiscript::fun(&TestDerivedType::derived_only_func), "derived_only_func");
m->add(chaiscript::fun(&derived_type_factory), "derived_type_factory");
m->add(chaiscript::fun(&more_derived_type_factory), "more_derived_type_factory");
m->add(chaiscript::fun(&null_factory), "null_factory");
m->add(chaiscript::fun(&TestDerivedType::func), "func");
m->add(chaiscript::fun(&TestBaseType::func), "func");
m->add(chaiscript::fun(&TestBaseType::val), "val");
m->add(chaiscript::fun(&TestBaseType::const_val), "const_val");
m->add(chaiscript::fun(&TestBaseType::const_val_ptr), "const_val_ptr");
m->add(chaiscript::fun(&TestBaseType::get_const_val_ptr), "get_const_val_ptr");
m->add(chaiscript::fun(&TestBaseType::base_only_func), "base_only_func");
m->add(chaiscript::fun(&TestBaseType::set_string_val), "set_string_val");
m->add(chaiscript::fun(&TestBaseType::mdarray), "mdarray");
chaiscript::bootstrap::array<int[2][3][5]>("IntArray_2_3_5", *m);
chaiscript::bootstrap::array<int[3][5]>("IntArray_3_5", *m);
chaiscript::bootstrap::array<int[5]>("IntArray_5", *m);
// member that is a function
m->add(chaiscript::fun(&TestBaseType::func_member), "func_member");
m->add(chaiscript::fun(&get_new_int), "get_new_int");
m->add_global_const(chaiscript::const_var(TestValue1), "TestValue1");
m->add(chaiscript::user_type<TestEnum>(), "TestEnum");
m->add(chaiscript::fun(&to_int), "to_int");
m->add(chaiscript::fun(&TestBaseType::constMe), "constMe");
m->add(chaiscript::type_conversion<TestBaseType, Type2>([](const TestBaseType &t_bt) { return Type2(t_bt); }));
m->add(chaiscript::fun(&Type2::get_val), "get_val");
m->add(chaiscript::fun(&Type2::get_str), "get_str");
m->add(chaiscript::type_conversion<const char *, std::string>());
m->add(chaiscript::constructor<Type2(const TestBaseType &)>(), "Type2");
m->add(chaiscript::fun(&update_shared_ptr), "update_shared_ptr");
m->add(chaiscript::fun(&nullify_shared_ptr), "nullify_shared_ptr");
return m;
}
#ifdef __llvm__
#pragma clang diagnostic pop
#endif
#ifdef CHAISCRIPT_MSVC
#pragma warning(pop)
#endif
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

ChaiScript是一个嵌入式脚本语言,专为与C++无缝集成而设计。
暂无标签
BSD-3-Clause
使用 BSD-3-Clause 开源许可协议
, BSD-3-Clause
使用 BSD-3-Clause 开源许可协议
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/electron/ChaiScript.git
git@gitee.com:electron/ChaiScript.git
electron
ChaiScript
ChaiScript
develop
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /