mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2026-07-30 16:26:28 +08:00
* Fix #690: Apply clang-format consistently with CI Applied clang-format-19 to all source files to enforce consistent formatting according to the existing .clang-format configuration. Added auto-clang-format GitHub Actions workflow (from cpp-best-practices/cmake_template) that runs on pull requests to automatically format and commit any style violations going forward. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
1cbbba38f9
commit
9680c93bd1
@ -1,10 +1,14 @@
|
|||||||
# clang-format: 11
|
# clang-format: 19
|
||||||
AccessModifierOffset: -2
|
AccessModifierOffset: -2
|
||||||
AlignAfterOpenBracket: Align
|
AlignAfterOpenBracket: Align
|
||||||
AlignConsecutiveBitFields: false
|
AlignConsecutiveBitFields: false
|
||||||
AllowShortBlocksOnASingleLine: false
|
AllowShortBlocksOnASingleLine: Always
|
||||||
|
AllowShortCaseLabelsOnASingleLine: true
|
||||||
|
AllowShortEnumsOnASingleLine: true
|
||||||
AllowShortFunctionsOnASingleLine: Inline
|
AllowShortFunctionsOnASingleLine: Inline
|
||||||
|
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
|
||||||
AllowShortLambdasOnASingleLine: All
|
AllowShortLambdasOnASingleLine: All
|
||||||
|
AllowShortLoopsOnASingleLine: true
|
||||||
AlwaysBreakTemplateDeclarations: true
|
AlwaysBreakTemplateDeclarations: true
|
||||||
BasedOnStyle: WebKit
|
BasedOnStyle: WebKit
|
||||||
BinPackArguments: true
|
BinPackArguments: true
|
||||||
@ -13,12 +17,14 @@ BreakBeforeBraces: Attach
|
|||||||
ColumnLimit: 0
|
ColumnLimit: 0
|
||||||
Cpp11BracedListStyle: true
|
Cpp11BracedListStyle: true
|
||||||
FixNamespaceComments: true
|
FixNamespaceComments: true
|
||||||
|
IfMacros: ['SECTION']
|
||||||
IncludeBlocks: Preserve
|
IncludeBlocks: Preserve
|
||||||
IndentCaseLabels: true
|
IndentCaseLabels: true
|
||||||
IndentPPDirectives: None
|
IndentPPDirectives: None
|
||||||
IndentWidth: 2
|
IndentWidth: 2
|
||||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||||
NamespaceIndentation: All
|
NamespaceIndentation: All
|
||||||
|
PackConstructorInitializers: CurrentLine
|
||||||
PenaltyBreakBeforeFirstCallParameter: 200
|
PenaltyBreakBeforeFirstCallParameter: 200
|
||||||
PenaltyBreakComment: 5
|
PenaltyBreakComment: 5
|
||||||
PenaltyBreakFirstLessLess: 50
|
PenaltyBreakFirstLessLess: 50
|
||||||
@ -27,6 +33,10 @@ PointerAlignment: Right
|
|||||||
SortIncludes: true
|
SortIncludes: true
|
||||||
SpaceAfterTemplateKeyword: false
|
SpaceAfterTemplateKeyword: false
|
||||||
SpaceBeforeCpp11BracedList: false
|
SpaceBeforeCpp11BracedList: false
|
||||||
|
SpaceBeforeParens: Custom
|
||||||
|
SpaceBeforeParensOptions:
|
||||||
|
AfterControlStatements: true
|
||||||
|
AfterIfMacros: false
|
||||||
SpaceInEmptyBlock: false
|
SpaceInEmptyBlock: false
|
||||||
Standard: Latest
|
Standard: Latest
|
||||||
TabWidth: 2
|
TabWidth: 2
|
||||||
|
|||||||
27
.github/workflows/auto-clang-format.yml
vendored
Normal file
27
.github/workflows/auto-clang-format.yml
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
name: auto-clang-format
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- develop
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
- uses: DoozyX/clang-format-lint-action@v0.20
|
||||||
|
with:
|
||||||
|
source: '.'
|
||||||
|
exclude: './third_party ./external ./unittests/catch.hpp'
|
||||||
|
extensions: 'h,cpp,hpp'
|
||||||
|
clangFormatVersion: 19
|
||||||
|
inplace: True
|
||||||
|
- uses: EndBug/add-and-commit@v9
|
||||||
|
with:
|
||||||
|
author_name: Clang Robot
|
||||||
|
author_email: robot@example.com
|
||||||
|
message: ':art: Committing clang-format changes'
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
@ -11,14 +11,14 @@
|
|||||||
#ifndef CHAISCRIPT_EMSCRIPTEN_EVAL_HPP_
|
#ifndef CHAISCRIPT_EMSCRIPTEN_EVAL_HPP_
|
||||||
#define CHAISCRIPT_EMSCRIPTEN_EVAL_HPP_
|
#define CHAISCRIPT_EMSCRIPTEN_EVAL_HPP_
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <chaiscript/chaiscript.hpp>
|
#include <chaiscript/chaiscript.hpp>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
inline chaiscript::ChaiScript &get_chai_instance() {
|
inline chaiscript::ChaiScript &get_chai_instance() {
|
||||||
static chaiscript::ChaiScript chai;
|
static chaiscript::ChaiScript chai;
|
||||||
return chai;
|
return chai;
|
||||||
}
|
}
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
inline void chaiscript_eval(const std::string &input) {
|
inline void chaiscript_eval(const std::string &input) {
|
||||||
|
|||||||
@ -18,11 +18,11 @@
|
|||||||
|
|
||||||
#include "dispatchkit/function_call.hpp"
|
#include "dispatchkit/function_call.hpp"
|
||||||
|
|
||||||
//#include "dispatchkit/dispatchkit.hpp"
|
// #include "dispatchkit/dispatchkit.hpp"
|
||||||
#include "dispatchkit/bootstrap.hpp"
|
#include "dispatchkit/bootstrap.hpp"
|
||||||
#include "dispatchkit/bootstrap_stl.hpp"
|
#include "dispatchkit/bootstrap_stl.hpp"
|
||||||
#include "dispatchkit/operators.hpp"
|
#include "dispatchkit/operators.hpp"
|
||||||
//#include "dispatchkit/boxed_value.hpp"
|
// #include "dispatchkit/boxed_value.hpp"
|
||||||
#include "dispatchkit/register_function.hpp"
|
#include "dispatchkit/register_function.hpp"
|
||||||
#include "language/chaiscript_prelude.hpp"
|
#include "language/chaiscript_prelude.hpp"
|
||||||
#include "utility/json_wrap.hpp"
|
#include "utility/json_wrap.hpp"
|
||||||
|
|||||||
@ -65,7 +65,6 @@ namespace chaiscript {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool is_explicit() const noexcept { return m_option_explicit; }
|
bool is_explicit() const noexcept { return m_option_explicit; }
|
||||||
|
|
||||||
void set_explicit(const bool t_explicit) noexcept { m_option_explicit = t_explicit; }
|
void set_explicit(const bool t_explicit) noexcept { m_option_explicit = t_explicit; }
|
||||||
|
|||||||
@ -148,11 +148,11 @@ namespace chaiscript {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Proxy_Function implementation designed for creating a new
|
* A Proxy_Function implementation designed for creating a new
|
||||||
* Dynamic_Object
|
* Dynamic_Object
|
||||||
* that is automatically guarded based on the first param based on the
|
* that is automatically guarded based on the first param based on the
|
||||||
* param's type name
|
* param's type name
|
||||||
*/
|
*/
|
||||||
class Dynamic_Object_Constructor final : public Proxy_Function_Base {
|
class Dynamic_Object_Constructor final : public Proxy_Function_Base {
|
||||||
public:
|
public:
|
||||||
Dynamic_Object_Constructor(std::string t_type_name, const Proxy_Function &t_func)
|
Dynamic_Object_Constructor(std::string t_type_name, const Proxy_Function &t_func)
|
||||||
|
|||||||
@ -64,7 +64,7 @@ namespace chaiscript::dispatch::detail {
|
|||||||
Function_Signature(Ret (Class::*f)(Param...) volatile &) -> Function_Signature<Ret, Function_Params<volatile Class &, Param...>, false, true>;
|
Function_Signature(Ret (Class::*f)(Param...) volatile &) -> Function_Signature<Ret, Function_Params<volatile Class &, Param...>, false, true>;
|
||||||
|
|
||||||
template<typename Ret, typename Class, typename... Param>
|
template<typename Ret, typename Class, typename... Param>
|
||||||
Function_Signature(Ret (Class::*f)(Param...) volatile &noexcept)
|
Function_Signature(Ret (Class::*f)(Param...) volatile & noexcept)
|
||||||
-> Function_Signature<Ret, Function_Params<volatile Class &, Param...>, true, true>;
|
-> Function_Signature<Ret, Function_Params<volatile Class &, Param...>, true, true>;
|
||||||
|
|
||||||
template<typename Ret, typename Class, typename... Param>
|
template<typename Ret, typename Class, typename... Param>
|
||||||
@ -72,20 +72,20 @@ namespace chaiscript::dispatch::detail {
|
|||||||
-> Function_Signature<Ret, Function_Params<volatile const Class &, Param...>, false, true>;
|
-> Function_Signature<Ret, Function_Params<volatile const Class &, Param...>, false, true>;
|
||||||
|
|
||||||
template<typename Ret, typename Class, typename... Param>
|
template<typename Ret, typename Class, typename... Param>
|
||||||
Function_Signature(Ret (Class::*f)(Param...) volatile const &noexcept)
|
Function_Signature(Ret (Class::*f)(Param...) volatile const & noexcept)
|
||||||
-> Function_Signature<Ret, Function_Params<volatile const Class &, Param...>, true, true>;
|
-> Function_Signature<Ret, Function_Params<volatile const Class &, Param...>, true, true>;
|
||||||
|
|
||||||
template<typename Ret, typename Class, typename... Param>
|
template<typename Ret, typename Class, typename... Param>
|
||||||
Function_Signature(Ret (Class::*f)(Param...) &) -> Function_Signature<Ret, Function_Params<Class &, Param...>, false, true>;
|
Function_Signature(Ret (Class::*f)(Param...) &) -> Function_Signature<Ret, Function_Params<Class &, Param...>, false, true>;
|
||||||
|
|
||||||
template<typename Ret, typename Class, typename... Param>
|
template<typename Ret, typename Class, typename... Param>
|
||||||
Function_Signature(Ret (Class::*f)(Param...) &noexcept) -> Function_Signature<Ret, Function_Params<Class &, Param...>, true, true>;
|
Function_Signature(Ret (Class::*f)(Param...) & noexcept) -> Function_Signature<Ret, Function_Params<Class &, Param...>, true, true>;
|
||||||
|
|
||||||
template<typename Ret, typename Class, typename... Param>
|
template<typename Ret, typename Class, typename... Param>
|
||||||
Function_Signature(Ret (Class::*f)(Param...) const &) -> Function_Signature<Ret, Function_Params<const Class &, Param...>, false, true>;
|
Function_Signature(Ret (Class::*f)(Param...) const &) -> Function_Signature<Ret, Function_Params<const Class &, Param...>, false, true>;
|
||||||
|
|
||||||
template<typename Ret, typename Class, typename... Param>
|
template<typename Ret, typename Class, typename... Param>
|
||||||
Function_Signature(Ret (Class::*f)(Param...) const &noexcept) -> Function_Signature<Ret, Function_Params<const Class &, Param...>, true, true>;
|
Function_Signature(Ret (Class::*f)(Param...) const & noexcept) -> Function_Signature<Ret, Function_Params<const Class &, Param...>, true, true>;
|
||||||
|
|
||||||
// && reference specifier
|
// && reference specifier
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ namespace chaiscript::dispatch::detail {
|
|||||||
Function_Signature(Ret (Class::*f)(Param...) volatile &&) -> Function_Signature<Ret, Function_Params<volatile Class &&, Param...>, false, true>;
|
Function_Signature(Ret (Class::*f)(Param...) volatile &&) -> Function_Signature<Ret, Function_Params<volatile Class &&, Param...>, false, true>;
|
||||||
|
|
||||||
template<typename Ret, typename Class, typename... Param>
|
template<typename Ret, typename Class, typename... Param>
|
||||||
Function_Signature(Ret (Class::*f)(Param...) volatile &&noexcept)
|
Function_Signature(Ret (Class::*f)(Param...) volatile && noexcept)
|
||||||
-> Function_Signature<Ret, Function_Params<volatile Class &&, Param...>, true, true>;
|
-> Function_Signature<Ret, Function_Params<volatile Class &&, Param...>, true, true>;
|
||||||
|
|
||||||
template<typename Ret, typename Class, typename... Param>
|
template<typename Ret, typename Class, typename... Param>
|
||||||
@ -101,20 +101,20 @@ namespace chaiscript::dispatch::detail {
|
|||||||
-> Function_Signature<Ret, Function_Params<volatile const Class &&, Param...>, false, true>;
|
-> Function_Signature<Ret, Function_Params<volatile const Class &&, Param...>, false, true>;
|
||||||
|
|
||||||
template<typename Ret, typename Class, typename... Param>
|
template<typename Ret, typename Class, typename... Param>
|
||||||
Function_Signature(Ret (Class::*f)(Param...) volatile const &&noexcept)
|
Function_Signature(Ret (Class::*f)(Param...) volatile const && noexcept)
|
||||||
-> Function_Signature<Ret, Function_Params<volatile const Class &&, Param...>, true, true>;
|
-> Function_Signature<Ret, Function_Params<volatile const Class &&, Param...>, true, true>;
|
||||||
|
|
||||||
template<typename Ret, typename Class, typename... Param>
|
template<typename Ret, typename Class, typename... Param>
|
||||||
Function_Signature(Ret (Class::*f)(Param...) &&) -> Function_Signature<Ret, Function_Params<Class &&, Param...>, false, true>;
|
Function_Signature(Ret (Class::*f)(Param...) &&) -> Function_Signature<Ret, Function_Params<Class &&, Param...>, false, true>;
|
||||||
|
|
||||||
template<typename Ret, typename Class, typename... Param>
|
template<typename Ret, typename Class, typename... Param>
|
||||||
Function_Signature(Ret (Class::*f)(Param...) &&noexcept) -> Function_Signature<Ret, Function_Params<Class &&, Param...>, true, true>;
|
Function_Signature(Ret (Class::*f)(Param...) && noexcept) -> Function_Signature<Ret, Function_Params<Class &&, Param...>, true, true>;
|
||||||
|
|
||||||
template<typename Ret, typename Class, typename... Param>
|
template<typename Ret, typename Class, typename... Param>
|
||||||
Function_Signature(Ret (Class::*f)(Param...) const &&) -> Function_Signature<Ret, Function_Params<const Class &&, Param...>, false, true>;
|
Function_Signature(Ret (Class::*f)(Param...) const &&) -> Function_Signature<Ret, Function_Params<const Class &&, Param...>, false, true>;
|
||||||
|
|
||||||
template<typename Ret, typename Class, typename... Param>
|
template<typename Ret, typename Class, typename... Param>
|
||||||
Function_Signature(Ret (Class::*f)(Param...) const &&noexcept)
|
Function_Signature(Ret (Class::*f)(Param...) const && noexcept)
|
||||||
-> Function_Signature<Ret, Function_Params<const Class &&, Param...>, true, true>;
|
-> Function_Signature<Ret, Function_Params<const Class &&, Param...>, true, true>;
|
||||||
|
|
||||||
template<typename Ret, typename Class>
|
template<typename Ret, typename Class>
|
||||||
|
|||||||
@ -170,8 +170,8 @@ namespace chaiscript {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used internally for handling a return value from a Proxy_Function call
|
* Used internally for handling a return value from a Proxy_Function call
|
||||||
*/
|
*/
|
||||||
template<>
|
template<>
|
||||||
struct Handle_Return<Boxed_Number> {
|
struct Handle_Return<Boxed_Number> {
|
||||||
static Boxed_Value handle(const Boxed_Number &r) noexcept { return r.bv; }
|
static Boxed_Value handle(const Boxed_Number &r) noexcept { return r.bv; }
|
||||||
@ -182,8 +182,8 @@ namespace chaiscript {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used internally for handling a return value from a Proxy_Function call
|
* Used internally for handling a return value from a Proxy_Function call
|
||||||
*/
|
*/
|
||||||
template<>
|
template<>
|
||||||
struct Handle_Return<void> {
|
struct Handle_Return<void> {
|
||||||
static Boxed_Value handle() { return void_var(); }
|
static Boxed_Value handle() { return void_var(); }
|
||||||
|
|||||||
@ -165,13 +165,13 @@ namespace chaiscript {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pure virtual base class for all Proxy_Function implementations
|
* Pure virtual base class for all Proxy_Function implementations
|
||||||
* Proxy_Functions are a type erasure of type safe C++
|
* Proxy_Functions are a type erasure of type safe C++
|
||||||
* function calls. At runtime parameter types are expected to be
|
* function calls. At runtime parameter types are expected to be
|
||||||
* tested against passed in types.
|
* tested against passed in types.
|
||||||
* Dispatch_Engine only knows how to work with Proxy_Function, no other
|
* Dispatch_Engine only knows how to work with Proxy_Function, no other
|
||||||
* function classes.
|
* function classes.
|
||||||
*/
|
*/
|
||||||
class Proxy_Function_Base {
|
class Proxy_Function_Base {
|
||||||
public:
|
public:
|
||||||
virtual ~Proxy_Function_Base() = default;
|
virtual ~Proxy_Function_Base() = default;
|
||||||
|
|||||||
@ -32,9 +32,9 @@ namespace chaiscript {
|
|||||||
namespace chaiscript {
|
namespace chaiscript {
|
||||||
namespace exception {
|
namespace exception {
|
||||||
/**
|
/**
|
||||||
* Exception thrown when there is a mismatch in number of
|
* Exception thrown when there is a mismatch in number of
|
||||||
* parameters during Proxy_Function execution
|
* parameters during Proxy_Function execution
|
||||||
*/
|
*/
|
||||||
struct arity_error : std::range_error {
|
struct arity_error : std::range_error {
|
||||||
arity_error(int t_got, int t_expected)
|
arity_error(int t_got, int t_expected)
|
||||||
: std::range_error("Function dispatch arity mismatch")
|
: std::range_error("Function dispatch arity mismatch")
|
||||||
@ -54,9 +54,9 @@ namespace chaiscript {
|
|||||||
namespace dispatch {
|
namespace dispatch {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
/**
|
/**
|
||||||
* Used by Proxy_Function_Impl to return a list of all param types
|
* Used by Proxy_Function_Impl to return a list of all param types
|
||||||
* it contains.
|
* it contains.
|
||||||
*/
|
*/
|
||||||
template<typename Ret, typename... Params>
|
template<typename Ret, typename... Params>
|
||||||
std::vector<Type_Info> build_param_type_list(Ret (*)(Params...)) {
|
std::vector<Type_Info> build_param_type_list(Ret (*)(Params...)) {
|
||||||
/// \note somehow this is responsible for a large part of the code generation
|
/// \note somehow this is responsible for a large part of the code generation
|
||||||
@ -64,10 +64,10 @@ namespace chaiscript {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used by Proxy_Function_Impl to determine if it is equivalent to another
|
* Used by Proxy_Function_Impl to determine if it is equivalent to another
|
||||||
* Proxy_Function_Impl object. This function is primarily used to prevent
|
* Proxy_Function_Impl object. This function is primarily used to prevent
|
||||||
* registration of two functions with the exact same signatures
|
* registration of two functions with the exact same signatures
|
||||||
*/
|
*/
|
||||||
template<typename Ret, typename... Params>
|
template<typename Ret, typename... Params>
|
||||||
bool compare_types_cast(Ret (*)(Params...), const chaiscript::Function_Params ¶ms, const Type_Conversions_State &t_conversions) noexcept {
|
bool compare_types_cast(Ret (*)(Params...), const chaiscript::Function_Params ¶ms, const Type_Conversions_State &t_conversions) noexcept {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -542,9 +542,8 @@ namespace chaiscript {
|
|||||||
= detail::Cast_Helper<const std::pair<Boxed_Value, Boxed_Value> &>::cast(t_bv, nullptr);
|
= detail::Cast_Helper<const std::pair<Boxed_Value, Boxed_Value> &>::cast(t_bv, nullptr);
|
||||||
|
|
||||||
auto pair = std::make_pair(
|
auto pair = std::make_pair(
|
||||||
detail::Cast_Helper<Left>::cast(from_pair.first, nullptr),
|
detail::Cast_Helper<Left>::cast(from_pair.first, nullptr),
|
||||||
detail::Cast_Helper<Right>::cast(from_pair.second, nullptr)
|
detail::Cast_Helper<Right>::cast(from_pair.second, nullptr));
|
||||||
);
|
|
||||||
|
|
||||||
return Boxed_Value(std::move(pair));
|
return Boxed_Value(std::move(pair));
|
||||||
};
|
};
|
||||||
|
|||||||
@ -593,13 +593,13 @@ namespace chaiscript {
|
|||||||
|
|
||||||
} // namespace exception
|
} // namespace exception
|
||||||
|
|
||||||
//static
|
// static
|
||||||
bool AST_Node::get_bool_condition(const Boxed_Value &t_bv, const chaiscript::detail::Dispatch_State &t_ss) {
|
bool AST_Node::get_bool_condition(const Boxed_Value &t_bv, const chaiscript::detail::Dispatch_State &t_ss) {
|
||||||
try {
|
try {
|
||||||
return t_ss->boxed_cast<bool>(t_bv);
|
return t_ss->boxed_cast<bool>(t_bv);
|
||||||
} catch (const exception::bad_boxed_cast &) {
|
} catch (const exception::bad_boxed_cast &) {
|
||||||
throw exception::eval_error("Condition not boolean");
|
throw exception::eval_error("Condition not boolean");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace parser {
|
namespace parser {
|
||||||
|
|||||||
@ -137,8 +137,9 @@ namespace chaiscript {
|
|||||||
m_engine.add(fun([this](const std::string &s) { m_print_handler(s + "\n"); }), "println_string");
|
m_engine.add(fun([this](const std::string &s) { m_print_handler(s + "\n"); }), "println_string");
|
||||||
|
|
||||||
m_engine.add(fun([this](const std::function<void(const std::string &)> &t_handler) {
|
m_engine.add(fun([this](const std::function<void(const std::string &)> &t_handler) {
|
||||||
m_print_handler = t_handler;
|
m_print_handler = t_handler;
|
||||||
}), "set_print_handler");
|
}),
|
||||||
|
"set_print_handler");
|
||||||
|
|
||||||
m_engine.add(fun([this](const std::function<std::string(const std::string &)> &t_reader) {
|
m_engine.add(fun([this](const std::function<std::string(const std::string &)> &t_reader) {
|
||||||
m_file_reader = t_reader;
|
m_file_reader = t_reader;
|
||||||
@ -291,7 +292,6 @@ namespace chaiscript {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// \brief Set a custom handler for print output, used by both print_string and println_string
|
/// \brief Set a custom handler for print output, used by both print_string and println_string
|
||||||
/// \param[in] t_handler Function to call with the string to print
|
/// \param[in] t_handler Function to call with the string to print
|
||||||
void set_print_handler(std::function<void(const std::string &)> t_handler) {
|
void set_print_handler(std::function<void(const std::string &)> t_handler) {
|
||||||
|
|||||||
@ -10,13 +10,13 @@
|
|||||||
#ifndef CHAISCRIPT_EVAL_HPP_
|
#ifndef CHAISCRIPT_EVAL_HPP_
|
||||||
#define CHAISCRIPT_EVAL_HPP_
|
#define CHAISCRIPT_EVAL_HPP_
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <algorithm>
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -389,11 +389,11 @@ namespace chaiscript {
|
|||||||
|
|
||||||
// static and public so we can use this to process Switch_AST_Node case equality
|
// static and public so we can use this to process Switch_AST_Node case equality
|
||||||
static Boxed_Value do_oper(const chaiscript::detail::Dispatch_State &t_ss,
|
static Boxed_Value do_oper(const chaiscript::detail::Dispatch_State &t_ss,
|
||||||
Operators::Opers t_oper,
|
Operators::Opers t_oper,
|
||||||
const std::string &t_oper_string,
|
const std::string &t_oper_string,
|
||||||
const Boxed_Value &t_lhs,
|
const Boxed_Value &t_lhs,
|
||||||
const Boxed_Value &t_rhs,
|
const Boxed_Value &t_rhs,
|
||||||
std::atomic_uint_fast32_t &t_loc) {
|
std::atomic_uint_fast32_t &t_loc) {
|
||||||
try {
|
try {
|
||||||
if (t_oper != Operators::Opers::invalid && t_lhs.get_type_info().is_arithmetic() && t_rhs.get_type_info().is_arithmetic()) {
|
if (t_oper != Operators::Opers::invalid && t_lhs.get_type_info().is_arithmetic() && t_rhs.get_type_info().is_arithmetic()) {
|
||||||
// If it's an arithmetic operation we want to short circuit dispatch
|
// If it's an arithmetic operation we want to short circuit dispatch
|
||||||
@ -1271,8 +1271,7 @@ namespace chaiscript {
|
|||||||
const auto process_statement = [&](const AST_Node_Impl<T> &stmt) {
|
const auto process_statement = [&](const AST_Node_Impl<T> &stmt) {
|
||||||
if (stmt.identifier == AST_Node_Type::Def) {
|
if (stmt.identifier == AST_Node_Type::Def) {
|
||||||
const auto &def_node = static_cast<const Def_AST_Node<T> &>(stmt);
|
const auto &def_node = static_cast<const Def_AST_Node<T> &>(stmt);
|
||||||
target_ns[def_node.children[0]->text] =
|
target_ns[def_node.children[0]->text] = Boxed_Value(Def_AST_Node<T>::make_proxy_function(def_node, t_ss));
|
||||||
Boxed_Value(Def_AST_Node<T>::make_proxy_function(def_node, t_ss));
|
|
||||||
} else if (stmt.identifier == AST_Node_Type::Assign_Decl
|
} else if (stmt.identifier == AST_Node_Type::Assign_Decl
|
||||||
|| stmt.identifier == AST_Node_Type::Const_Assign_Decl) {
|
|| stmt.identifier == AST_Node_Type::Const_Assign_Decl) {
|
||||||
const auto &var_name = stmt.children[0]->text;
|
const auto &var_name = stmt.children[0]->text;
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
#ifndef CHAISCRIPT_SIMPLEJSON_WRAP_HPP
|
#ifndef CHAISCRIPT_SIMPLEJSON_WRAP_HPP
|
||||||
#define CHAISCRIPT_SIMPLEJSON_WRAP_HPP
|
#define CHAISCRIPT_SIMPLEJSON_WRAP_HPP
|
||||||
|
|
||||||
#include "json.hpp"
|
|
||||||
#include "../dispatchkit/dynamic_object.hpp"
|
#include "../dispatchkit/dynamic_object.hpp"
|
||||||
|
#include "json.hpp"
|
||||||
|
|
||||||
namespace chaiscript {
|
namespace chaiscript {
|
||||||
class json_wrap {
|
class json_wrap {
|
||||||
|
|||||||
@ -605,7 +605,9 @@ TEST_CASE("Utility_Test utility class wrapper for enum") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Issue #601: add_class for enums should work directly with ChaiScript reference
|
// Issue #601: add_class for enums should work directly with ChaiScript reference
|
||||||
enum class Issue601_EnumClass { Apple, Banana, Pear };
|
enum class Issue601_EnumClass { Apple,
|
||||||
|
Banana,
|
||||||
|
Pear };
|
||||||
|
|
||||||
TEST_CASE("Issue 601: add_class enum with ChaiScript reference directly") {
|
TEST_CASE("Issue 601: add_class enum with ChaiScript reference directly") {
|
||||||
chaiscript::ChaiScript_Basic chai(create_chaiscript_stdlib(), create_chaiscript_parser());
|
chaiscript::ChaiScript_Basic chai(create_chaiscript_stdlib(), create_chaiscript_parser());
|
||||||
@ -626,7 +628,9 @@ TEST_CASE("Issue 601: add_class enum with ChaiScript reference directly") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Also test non-scoped enum directly with ChaiScript reference
|
// Also test non-scoped enum directly with ChaiScript reference
|
||||||
enum Issue601_PlainEnum { Issue601_Red = 0, Issue601_Green = 1, Issue601_Blue = 2 };
|
enum Issue601_PlainEnum { Issue601_Red = 0,
|
||||||
|
Issue601_Green = 1,
|
||||||
|
Issue601_Blue = 2 };
|
||||||
|
|
||||||
TEST_CASE("Issue 601: add_class plain enum with ChaiScript reference directly") {
|
TEST_CASE("Issue 601: add_class plain enum with ChaiScript reference directly") {
|
||||||
chaiscript::ChaiScript_Basic chai(create_chaiscript_stdlib(), create_chaiscript_parser());
|
chaiscript::ChaiScript_Basic chai(create_chaiscript_stdlib(), create_chaiscript_parser());
|
||||||
@ -952,7 +956,7 @@ TEST_CASE("Pair conversions") {
|
|||||||
const auto p = chai.eval<std::pair<std::string, std::string>>(R"cs(
|
const auto p = chai.eval<std::pair<std::string, std::string>>(R"cs(
|
||||||
Pair("chai", "script");
|
Pair("chai", "script");
|
||||||
)cs");
|
)cs");
|
||||||
CHECK(p.first == std::string{ "chai" });
|
CHECK(p.first == std::string{"chai"});
|
||||||
CHECK(p.second == "script");
|
CHECK(p.second == "script");
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
@ -1532,7 +1536,8 @@ TEST_CASE("ChaiScript default has all functions") {
|
|||||||
TEST_CASE("Issue #421 - Switch with type_conversion does not compare destroyed objects") {
|
TEST_CASE("Issue #421 - Switch with type_conversion does not compare destroyed objects") {
|
||||||
struct MyType {
|
struct MyType {
|
||||||
int value;
|
int value;
|
||||||
explicit MyType(int v) : value(v) {}
|
explicit MyType(int v)
|
||||||
|
: value(v) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
chaiscript::ChaiScript_Basic chai(create_chaiscript_stdlib(), create_chaiscript_parser());
|
chaiscript::ChaiScript_Basic chai(create_chaiscript_stdlib(), create_chaiscript_parser());
|
||||||
@ -1755,51 +1760,50 @@ TEST_CASE("push_back on script vector with vector_conversion") {
|
|||||||
// Register a C++ function that accepts the converted type, so we can
|
// Register a C++ function that accepts the converted type, so we can
|
||||||
// verify that vector_conversion actually works for passing vectors
|
// verify that vector_conversion actually works for passing vectors
|
||||||
chai.add(chaiscript::fun([](const std::vector<std::string> &v) -> std::string {
|
chai.add(chaiscript::fun([](const std::vector<std::string> &v) -> std::string {
|
||||||
std::string result;
|
std::string result;
|
||||||
for (const auto &s : v) {
|
for (const auto &s : v) {
|
||||||
if (!result.empty()) { result += ","; }
|
if (!result.empty()) { result += ","; }
|
||||||
result += s;
|
result += s;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}), "join_strings");
|
}),
|
||||||
|
"join_strings");
|
||||||
|
|
||||||
// push_back on an empty script-created vector must be visible
|
// push_back on an empty script-created vector must be visible
|
||||||
CHECK(chai.eval<bool>(
|
CHECK(chai.eval<bool>(
|
||||||
"auto x = [];"
|
"auto x = [];"
|
||||||
"x.push_back(\"Hello\");"
|
"x.push_back(\"Hello\");"
|
||||||
"x.size() == 1"
|
"x.size() == 1"));
|
||||||
));
|
|
||||||
|
|
||||||
// push_back on a vector with initial elements must grow correctly
|
// push_back on a vector with initial elements must grow correctly
|
||||||
CHECK(chai.eval<bool>(
|
CHECK(chai.eval<bool>(
|
||||||
"auto y = [\"a\", \"b\"];"
|
"auto y = [\"a\", \"b\"];"
|
||||||
"y.push_back(\"c\");"
|
"y.push_back(\"c\");"
|
||||||
"y.push_back(\"d\");"
|
"y.push_back(\"d\");"
|
||||||
"y.size() == 4"
|
"y.size() == 4"));
|
||||||
));
|
|
||||||
|
|
||||||
// Verify the actual content is preserved after push_back
|
// Verify the actual content is preserved after push_back
|
||||||
CHECK(chai.eval<std::string>(
|
CHECK(chai.eval<std::string>(
|
||||||
"auto z = [];"
|
"auto z = [];"
|
||||||
"z.push_back(\"World\");"
|
"z.push_back(\"World\");"
|
||||||
"z[0]"
|
"z[0]")
|
||||||
) == "World");
|
== "World");
|
||||||
|
|
||||||
// Round-trip: build a vector in script, push_back elements, then pass it
|
// Round-trip: build a vector in script, push_back elements, then pass it
|
||||||
// to a C++ function via vector_conversion and verify the contents
|
// to a C++ function via vector_conversion and verify the contents
|
||||||
CHECK(chai.eval<std::string>(
|
CHECK(chai.eval<std::string>(
|
||||||
"auto v = [\"one\", \"two\"];"
|
"auto v = [\"one\", \"two\"];"
|
||||||
"v.push_back(\"three\");"
|
"v.push_back(\"three\");"
|
||||||
"join_strings(v)"
|
"join_strings(v)")
|
||||||
) == "one,two,three");
|
== "one,two,three");
|
||||||
|
|
||||||
// Verify conversion works on a freshly created vector too
|
// Verify conversion works on a freshly created vector too
|
||||||
CHECK(chai.eval<std::string>(
|
CHECK(chai.eval<std::string>(
|
||||||
"auto w = [];"
|
"auto w = [];"
|
||||||
"w.push_back(\"hello\");"
|
"w.push_back(\"hello\");"
|
||||||
"w.push_back(\"world\");"
|
"w.push_back(\"world\");"
|
||||||
"join_strings(w)"
|
"join_strings(w)")
|
||||||
) == "hello,world");
|
== "hello,world");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Regression test for issue #607: AST_Node_Trace must be a complete type
|
// Regression test for issue #607: AST_Node_Trace must be a complete type
|
||||||
@ -1962,20 +1966,23 @@ TEST_CASE("Namespace block rejects non-declaration statements") {
|
|||||||
namespace bad {
|
namespace bad {
|
||||||
1 + 2
|
1 + 2
|
||||||
}
|
}
|
||||||
)"), chaiscript::exception::eval_error);
|
)"),
|
||||||
|
chaiscript::exception::eval_error);
|
||||||
|
|
||||||
CHECK_THROWS_AS(chai.eval(R"(
|
CHECK_THROWS_AS(chai.eval(R"(
|
||||||
namespace bad {
|
namespace bad {
|
||||||
print("hello")
|
print("hello")
|
||||||
}
|
}
|
||||||
)"), chaiscript::exception::eval_error);
|
)"),
|
||||||
|
chaiscript::exception::eval_error);
|
||||||
|
|
||||||
CHECK_THROWS_AS(chai.eval(R"(
|
CHECK_THROWS_AS(chai.eval(R"(
|
||||||
var x = 5
|
var x = 5
|
||||||
namespace bad {
|
namespace bad {
|
||||||
x = 10
|
x = 10
|
||||||
}
|
}
|
||||||
)"), chaiscript::exception::eval_error);
|
)"),
|
||||||
|
chaiscript::exception::eval_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("C++ runtime_error thrown from registered function is catchable in ChaiScript") {
|
TEST_CASE("C++ runtime_error thrown from registered function is catchable in ChaiScript") {
|
||||||
@ -2061,7 +2068,8 @@ TEST_CASE("Typed catch with no match propagates exception") {
|
|||||||
catch(string e) {
|
catch(string e) {
|
||||||
// wrong type, should not match
|
// wrong type, should not match
|
||||||
}
|
}
|
||||||
)"), chaiscript::Boxed_Value);
|
)"),
|
||||||
|
chaiscript::Boxed_Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Typed catch with no match still runs finally block") {
|
TEST_CASE("Typed catch with no match still runs finally block") {
|
||||||
@ -2078,7 +2086,8 @@ TEST_CASE("Typed catch with no match still runs finally block") {
|
|||||||
finally {
|
finally {
|
||||||
finally_ran = true
|
finally_ran = true
|
||||||
}
|
}
|
||||||
)"), chaiscript::Boxed_Value);
|
)"),
|
||||||
|
chaiscript::Boxed_Value);
|
||||||
|
|
||||||
CHECK(chai.eval<bool>("finally_ran") == true);
|
CHECK(chai.eval<bool>("finally_ran") == true);
|
||||||
}
|
}
|
||||||
@ -2087,13 +2096,14 @@ TEST_CASE("Multiple C++ exception types from registered functions") {
|
|||||||
chaiscript::ChaiScript_Basic chai(create_chaiscript_stdlib(), create_chaiscript_parser());
|
chaiscript::ChaiScript_Basic chai(create_chaiscript_stdlib(), create_chaiscript_parser());
|
||||||
|
|
||||||
chai.add(chaiscript::fun([](int which) -> int {
|
chai.add(chaiscript::fun([](int which) -> int {
|
||||||
switch (which) {
|
switch (which) {
|
||||||
case 0: throw std::runtime_error("runtime");
|
case 0: throw std::runtime_error("runtime");
|
||||||
case 1: throw std::out_of_range("range");
|
case 1: throw std::out_of_range("range");
|
||||||
case 2: throw std::logic_error("logic");
|
case 2: throw std::logic_error("logic");
|
||||||
default: return which;
|
default: return which;
|
||||||
}
|
}
|
||||||
}), "cpp_multi_throw");
|
}),
|
||||||
|
"cpp_multi_throw");
|
||||||
|
|
||||||
CHECK(chai.eval<int>(R"(
|
CHECK(chai.eval<int>(R"(
|
||||||
var catch_count = 0
|
var catch_count = 0
|
||||||
@ -2121,8 +2131,9 @@ TEST_CASE("Exception from C++ binary operator is catchable in ChaiScript") {
|
|||||||
chai.add(chaiscript::user_type<ThrowingType>(), "ThrowingType");
|
chai.add(chaiscript::user_type<ThrowingType>(), "ThrowingType");
|
||||||
chai.add(chaiscript::constructor<ThrowingType(int)>(), "ThrowingType");
|
chai.add(chaiscript::constructor<ThrowingType(int)>(), "ThrowingType");
|
||||||
chai.add(chaiscript::fun([](const ThrowingType &, const ThrowingType &) -> ThrowingType {
|
chai.add(chaiscript::fun([](const ThrowingType &, const ThrowingType &) -> ThrowingType {
|
||||||
throw std::runtime_error("cpp operator+ threw");
|
throw std::runtime_error("cpp operator+ threw");
|
||||||
}), "+");
|
}),
|
||||||
|
"+");
|
||||||
|
|
||||||
CHECK(chai.eval<bool>(R"(
|
CHECK(chai.eval<bool>(R"(
|
||||||
var caught = false
|
var caught = false
|
||||||
@ -2148,9 +2159,10 @@ TEST_CASE("Exception from C++ [] operator is catchable in ChaiScript") {
|
|||||||
chai.add(chaiscript::user_type<IndexableType>(), "IndexableType");
|
chai.add(chaiscript::user_type<IndexableType>(), "IndexableType");
|
||||||
chai.add(chaiscript::constructor<IndexableType(int)>(), "IndexableType");
|
chai.add(chaiscript::constructor<IndexableType(int)>(), "IndexableType");
|
||||||
chai.add(chaiscript::fun([](const IndexableType &, int idx) -> int {
|
chai.add(chaiscript::fun([](const IndexableType &, int idx) -> int {
|
||||||
if (idx < 0) { throw std::out_of_range("negative index"); }
|
if (idx < 0) { throw std::out_of_range("negative index"); }
|
||||||
return idx;
|
return idx;
|
||||||
}), "[]");
|
}),
|
||||||
|
"[]");
|
||||||
|
|
||||||
CHECK(chai.eval<int>("var obj = IndexableType(0); obj[5]") == 5);
|
CHECK(chai.eval<int>("var obj = IndexableType(0); obj[5]") == 5);
|
||||||
|
|
||||||
|
|||||||
@ -9,9 +9,9 @@
|
|||||||
#define CHAISCRIPT_NO_DYNLOAD
|
#define CHAISCRIPT_NO_DYNLOAD
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <chaiscript/chaiscript.hpp>
|
|
||||||
#include "../emscripten/chaiscript_eval.hpp"
|
#include "../emscripten/chaiscript_eval.hpp"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <chaiscript/chaiscript.hpp>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|||||||
@ -10,9 +10,9 @@
|
|||||||
#define CHAISCRIPT_NO_DYNLOAD
|
#define CHAISCRIPT_NO_DYNLOAD
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <chaiscript/chaiscript.hpp>
|
|
||||||
#include "../emscripten/chaiscript_eval.hpp"
|
#include "../emscripten/chaiscript_eval.hpp"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <chaiscript/chaiscript.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|||||||
@ -5,8 +5,8 @@
|
|||||||
|
|
||||||
Multi_Test_Chai::Multi_Test_Chai()
|
Multi_Test_Chai::Multi_Test_Chai()
|
||||||
: m_chai(new chaiscript::ChaiScript_Basic(
|
: m_chai(new chaiscript::ChaiScript_Basic(
|
||||||
chaiscript::Std_Lib::library(),
|
chaiscript::Std_Lib::library(),
|
||||||
std::make_unique<chaiscript::parser::ChaiScript_Parser<chaiscript::eval::Noop_Tracer, chaiscript::optimizer::Optimizer_Default>>())) {
|
std::make_unique<chaiscript::parser::ChaiScript_Parser<chaiscript::eval::Noop_Tracer, chaiscript::optimizer::Optimizer_Default>>())) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<chaiscript::ChaiScript_Basic> Multi_Test_Chai::get_chai() {
|
std::shared_ptr<chaiscript::ChaiScript_Basic> Multi_Test_Chai::get_chai() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user