1384 Commits

Author SHA1 Message Date
leftibot
1619d846da
Fix #607: Remove unnecessary forward declarations that cause C++20 build failures (#647)
The forward declarations of AST_Node_Trace and eval_error at the top of
chaiscript_common.hpp introduced these types as incomplete before the standard
library headers were fully processed. On clang/libc++ in C++20 mode, this
caused compilation errors because std::vector<AST_Node_Trace> was instantiated
while the type was still incomplete. Since the full definitions of both types
appear later in the same file (and nothing between the forward declarations
and the definitions references them), these forward declarations are unnecessary
and removing them prevents the incomplete type issue.

Co-authored-by: leftibot <leftibot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 13:42:40 -06:00
leftibot
7b45fe19fe
Fix #592: Local variable saw_eol in Class_Statements() was always true (#646)
The saw_eol variable in Class_Statements() was initialized to true and
only ever set back to true, making the "missing line separator" check
unreachable. The fix separates Def (block statement ending with }) from
Var_Decl (simple statement) so that Var_Decl sets saw_eol to false,
matching the pattern used in Statements() for simple expressions.

Co-authored-by: leftibot <leftibot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 08:32:27 -06:00
leftibot
e42497a8b3
Fix #256: ChaiScript::get_locals() does not show functions (#640)
* Fix #256: Expose get_function_objects() and get_scripting_objects() in public API

The ChaiScript_Basic public API only exposed get_locals() for inspecting
runtime state from C++, requiring users to work around this via
chai.eval("get_functions()") to access function objects. Added
get_function_objects() and get_scripting_objects() as public methods on
ChaiScript_Basic, delegating to the existing Dispatch_Engine methods,
matching the pattern already used by get_locals().

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Address review: add tests for get_scripting_objects()

Requested by @lefticus in PR #640 review.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: leftibot <leftibot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 07:57:09 -06:00
leftibot
fc574c320b
Fix #17: Add const variables in ChaiScript (#643)
* Fix #17: Add const local variable support to ChaiScript

Adds `const var`, `const auto`, and `const` as variable declaration
syntax that creates immutable local variables. A const_override flag
on Boxed_Value enables script-level constness without changing the
C++ type system integration. The parser, optimizer, and evaluator
are extended with Const_Var_Decl and Const_Assign_Decl AST nodes
that mirror their non-const counterparts but mark the value as const
after initialization.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Address review: remove const_override, set const flag directly on Type_Info

Replace the m_const_override bool on Boxed_Value::Data with a
Type_Info::make_const() method that sets the const bit in m_flags
directly. This ensures constness is visible everywhere consistently,
including places that check get_type_info().is_const() directly.

Requested by @lefticus in PR #643 review.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: leftibot <leftibot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 22:12:13 -06:00
Jason Turner
7d3c29085d
Merge pull request #638 from leftibot/fix/issue-284-way-to-disable-instring-eval
[WIP] Issue #284 — Way to disable instring_eval
2026-04-10 22:09:50 -06:00
olikraus
bcf2fdbf50 Fix #477: Handle \u unicode escape sequences in JSON parser
Convert \u escape sequences to proper UTF-8 characters instead of
passing through the literal \u notation. Supports the full BMP range
with correct 1, 2, 3, and 4-byte UTF-8 encoding.

Based on PR #483 by @olikraus, rebased onto current develop.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 19:49:48 -06:00
leftibot
f59eff9b2f
Fix #201: Suggestion: class Inheritance (#641)
* Fix #201: Add class inheritance support with Derived : Base syntax

Classes can now inherit methods and attributes from a base class using
C++-style syntax: `class Derived : Base { ... }`. Base class methods and
attributes are automatically available on derived objects. Derived classes
can override base methods by defining a method with the same name.
Inheritance relationships are tracked to support proper type matching
in the dispatch system.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Address review: use implicit derived-to-base matching instead of copying base class functions

Instead of copying all base class methods/attributes into derived classes,
make the type matching system recognize inheritance relationships. Base class
methods now naturally match derived objects through dynamic_object_typename_match,
and dispatch ordering ensures derived overrides are preferred over base methods.

This is simpler (net -25 lines) and avoids duplicating function registrations.

Requested by @lefticus in PR #641 review.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Add tests for passing derived objects to functions expecting Base

Tests cover: free functions calling base methods on derived objects,
polymorphic dispatch through containers, base attribute access on
derived objects, and multi-level inheritance (GrandChild : Derived : Base).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Add typed parameter tests for class inheritance

Use typed function signatures (e.g., `def call_do_something(Base obj)`)
instead of untyped parameters to test that derived objects are accepted
by functions expecting a base type, with correct polymorphic dispatch.

Requested by @lefticus in PR #641 review.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: leftibot <leftibot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 19:12:06 -06:00
dinghram
78d2de0ccf Fix #421: Switch with type_conversion compares destroyed objects
Add Function_Push_Pop to Switch_AST_Node case comparison to properly
manage the lifetime of temporaries created during type conversions.

Make Binary_Operator_AST_Node::do_oper static and public so it can be
reused by Switch_AST_Node for case equality checks, ensuring consistent
lifetime management across all operator invocations.

Original-PR: #422
Co-Authored-By: dinghram <don.inghram@gmail.com>
2026-04-10 18:18:17 -06:00
Jason Turner
da0322a8a2
Merge pull request #570 from totalgee/pair_conversion_2
Reimplement pair_conversion() helper
2026-04-10 17:58:33 -06:00
leftibot
34fea05bc2 Fix #284: Add raw string support to avoid instring_eval
Add C++11-style raw string literals (R"delimiter(content)delimiter") to
ChaiScript. Raw strings do not process escape sequences or perform string
interpolation, solving the issue where base85 encoded data containing ${
sequences would trigger unwanted instring_eval. The implementation adds
Raw_String_() and Raw_String() parser functions and hooks them into the
expression parser.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 22:09:42 -06:00
leftibot
84507f59ef Fix #12: Document reflection and introspection capabilities
Add comprehensive reflection documentation to cheatsheet.md covering type
inspection, object methods, Type_Info, function introspection, system
introspection, and Dynamic_Object reflection. Add missing global reflection
functions (type_name, is_type, function_exists, get_functions, get_objects,
type, dump_system, dump_object) and is_type_arithmetic to the Doxygen
prelude docs. Include a thorough test exercising all documented features.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 21:43:56 -06:00
Clemens Terasa
b44b987d4b chaiscript_eval: Fix warning by replacing lambda with ternary operator expression
Using GCC 13.3.0 I get warnings like the following:

```
In file included from .../ChaiScript/static_libs/../include/chaiscript/language/chaiscript_optimizer.hpp:10,
                 from .../ChaiScript/static_libs/../include/chaiscript/language/chaiscript_parser.hpp:26,
                 from .../ChaiScript/static_libs/chaiscript_parser.cpp:1:
.../ChaiScript/static_libs/../include/chaiscript/language/chaiscript_eval.hpp: In instantiation of ‘chaiscript::Boxed_Value chaiscript::eval::Global_Decl_AST_Node<T>::eval_internal(const chaiscript::detail::Dispatch_State&) const [with T = chaiscript::eval::Tracer<chaiscript::eval::Noop_Tracer_Detail>]’:
.../ChaiScript/static_libs/../include/chaiscript/language/chaiscript_eval.hpp:503:19:   required from here
.../ChaiScript/static_libs/../include/chaiscript/language/chaiscript_eval.hpp:504:28: warning: possibly dangling reference to a temporary [-Wdangling-reference]
  504 |         const std::string &idname = [&]() -> const std::string & {
      |                            ^~~~~~
.../ChaiScript/static_libs/../include/chaiscript/language/chaiscript_eval.hpp:510:10: note: the temporary was destroyed at the end of the full expression ‘<lambda closure object>chaiscript::eval::Global_Decl_AST_Node<chaiscript::eval::Tracer<chaiscript::eval::Noop_Tracer_Detail> >::eval_internal(const chaiscript::detail::Dispatch_State&) const::<lambda()>{((const chaiscript::eval::Global_Decl_AST_Node<chaiscript::eval::Tracer<chaiscript::eval::Noop_Tracer_Detail> >*)this)}.chaiscript::eval::Global_Decl_AST_Node<chaiscript::eval::Tracer<chaiscript::eval::Noop_Tracer_Detail> >::eval_internal(const chaiscript::detail::Dispatch_State&) const::<lambda()>()’
  504 |         const std::string &idname = [&]() -> const std::string & {
      |                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  505 |           if (this->children[0]->identifier == AST_Node_Type::Reference) {
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  506 |             return this->children[0]->children[0]->text;
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  507 |           } else {
      |           ~~~~~~~~
  508 |             return this->children[0]->text;
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  509 |           }
      |           ~
  510 |         }();
      |         ~^~
```

Fix this by replacing the lambda with a simple ternary operator
expression.
2025-02-19 20:04:17 +01:00
Clemens Terasa
681104b68f dispatchkit: boxed_value: Fix noexcept warning for Data ctor
Using gcc 13.3.0 I get many warnings like the following:

```
In file included from .../include/c++/13.3.0/bits/stl_iterator.h:85,
                 from .../include/c++/13.3.0/bits/stl_algobase.h:67,
                 from .../include/c++/13.3.0/bits/stl_tree.h:63,
                 from .../include/c++/13.3.0/map:62,
                 from .../ChaiScript/static_libs/../include/chaiscript/chaiscript_stdlib.hpp:10,
                 from .../ChaiScript/static_libs/chaiscript_stdlib.cpp:1:
.../include/c++/13.3.0/bits/stl_construct.h: In instantiation of ‘constexpr decltype (::new(void*(0)) _Tp) std::construct_at(_Tp*, _Args&& ...) [with _Tp = chaiscript::Boxed_Value::Data; _Args = {chaiscript::Type_Info, chaiscript::detail::Any, bool, std::nullptr_t, bool&}; decltype (::new(void*(0)) _Tp) = chaiscript::Boxed_Value::Data*]’:
.../include/c++/13.3.0/bits/stl_construct.h:115:21:   required from ‘constexpr void std::_Construct(_Tp*, _Args&& ...) [with _Tp = chaiscript::Boxed_Value::Data; _Args = {chaiscript::Type_Info, chaiscript::detail::Any, bool, std::nullptr_t, bool&}]’
.../include/c++/13.3.0/bits/alloc_traits.h:661:19:   required from ‘static constexpr void std::allocator_traits<std::allocator<void> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = chaiscript::Boxed_Value::Data; _Args = {chaiscript::Type_Info, chaiscript::detail::Any, bool, std::nullptr_t, bool&}; allocator_type = std::allocator<void>]’
.../include/c++/13.3.0/bits/shared_ptr_base.h:604:39:   required from ‘std::_Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp>::_Sp_counted_ptr_inplace(_Alloc, _Args&& ...) [with _Args = {chaiscript::Type_Info, chaiscript::detail::Any, bool, std::nullptr_t, bool&}; _Tp = chaiscript::Boxed_Value::Data; _Alloc = std::allocator<void>; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’
.../include/c++/13.3.0/bits/shared_ptr_base.h:971:16:   required from ‘std::__shared_count<_Lp>::__shared_count(_Tp*&, std::_Sp_alloc_shared_tag<_Alloc>, _Args&& ...) [with _Tp = chaiscript::Boxed_Value::Data; _Alloc = std::allocator<void>; _Args = {chaiscript::Type_Info, chaiscript::detail::Any, bool, std::nullptr_t, bool&}; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’
.../include/c++/13.3.0/bits/shared_ptr_base.h:1712:14:   required from ‘std::__shared_ptr<_Tp, _Lp>::__shared_ptr(std::_Sp_alloc_shared_tag<_Tp>, _Args&& ...) [with _Alloc = std::allocator<void>; _Args = {chaiscript::Type_Info, chaiscript::detail::Any, bool, std::nullptr_t, bool&}; _Tp = chaiscript::Boxed_Value::Data; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’
.../include/c++/13.3.0/bits/shared_ptr.h:464:59:   required from ‘std::shared_ptr<_Tp>::shared_ptr(std::_Sp_alloc_shared_tag<_Tp>, _Args&& ...) [with _Alloc = std::allocator<void>; _Args = {chaiscript::Type_Info, chaiscript::detail::Any, bool, std::nullptr_t, bool&}; _Tp = chaiscript::Boxed_Value::Data]’
.../include/c++/13.3.0/bits/shared_ptr.h:1009:14:   required from ‘std::shared_ptr<std::_NonArray<_Tp> > std::make_shared(_Args&& ...) [with _Tp = chaiscript::Boxed_Value::Data; _Args = {chaiscript::Type_Info, chaiscript::detail::Any, bool, std::nullptr_t, bool&}; _NonArray<_Tp> = chaiscript::Boxed_Value::Data]’
.../ChaiScript/static_libs/../include/chaiscript/language/../dispatchkit/boxed_value.hpp:74:38:   required from here
.../include/c++/13.3.0/bits/stl_construct.h:95:14: warning: noexcept-expression evaluates to ‘false’ because of a call to ‘chaiscript::Boxed_Value::Data::Data(const chaiscript::Type_Info&, chaiscript::detail::Any, bool, const void*, bool)’ [-Wnoexcept]
   95 |     noexcept(noexcept(::new((void*)0) _Tp(std::declval<_Args>()...)))
      |              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from .../ChaiScript/static_libs/../include/chaiscript/language/chaiscript_common.hpp:21,
                 from .../ChaiScript/static_libs/../include/chaiscript/chaiscript_stdlib.hpp:17:
.../ChaiScript/static_libs/../include/chaiscript/language/../dispatchkit/boxed_value.hpp:34:7: note: but ‘chaiscript::Boxed_Value::Data::Data(const chaiscript::Type_Info&, chaiscript::detail::Any, bool, const void*, bool)’ does not throw; perhaps it should be declared ‘noexcept’
   34 |       Data(const Type_Info &ti, chaiscript::detail::Any to, bool is_ref, const void *t_void_ptr, bool t_return_value)
      |       ^~~~
/
```

Fix this by adding a noexcept like the warning suggests.
2025-02-19 20:04:17 +01:00
Rob Loach
406a7ba1ef
Merge pull request #575 from stephenberry/develop
Added virtual destructor for ChaiScript_Basic
2024-02-20 12:52:52 -05:00
FellowTraveler
0870cb5a3a Add C++20 support
ChaiScript now successfully builds on my Mac with C++20, and passes 100% of the unit tests.
2023-06-18 06:42:51 -05:00
Stephen Berry
7cd229cf26 Added virtual destructor for ChaiScript_Basic
ChaiScript inherits from ChaiScript_Basic, so this is good practice.
I also need to be able to inherit from ChaiScript and dynamic cast, which is impossible without this destructor.
2021-07-28 09:04:38 -05:00
Glen Fraser
5722a5177d Fix crash with out of bounds index (issue #572) 2021-07-08 18:55:36 +02:00
Glen Fraser
69476967ae Reimplement pair_conversion() helper
- resolves issue #563.
2021-06-18 16:40:38 +02:00
Bernd Amend
0f37802aba move namespace json into the chaiscript namespace #486 2021-05-24 23:31:31 +02:00
Bernd Amend
cff6a0aced change .clang-format and reformat code with clang-format 11
I initially tried to use the existing .clang-format file,
but it does not match the code style (at least with clang-format 11)
and the formatting is not consistent across files.
Therefore, I decided to rewrite the .clang-format with some personal
preferences.

Used command
  find . -iname "*.hpp" -o -iname "*.cpp" | xargs clang-format -i -style=file
2021-05-24 10:44:15 +02:00
Bernd Amend
a4fd5371bd fix handling of $ in strings ChaiScript#553 2021-05-23 12:05:33 +02:00
Bernd Amend
82ef037912 fix vs2019 build 2021-05-22 23:53:31 +02:00
Bernd Amend
7aea27412d make is_nothrow_forward_constructible_v static (warning from gcc 7) 2021-05-22 18:45:12 +02:00
Bernd Amend
8ee033cf89 remove not required () 2021-05-22 18:45:12 +02:00
Bernd Amend
39f7aa0900 remove trailing spaces 2021-05-22 18:45:12 +02:00
Bernd Amend
32723fcbc0 fix clangs -Wshadow warning 2021-05-22 18:45:12 +02:00
Bernd Amend
14e9ec6e97 fix implicit conversion warnings by making them explicit 2021-05-22 18:45:12 +02:00
Bernd Amend
532f044bd3 remove trailing ; 2021-05-22 18:45:12 +02:00
Bernd Amend
b5d81613cf cmake suppress some clang compiler warnings 2021-05-22 18:45:12 +02:00
Bernd Amend
1302e28e32 replace the deprecated is_pod_v with is_trivial_v
is_pod_v was deprecated in C++20, is_pod_v can be
replaced with is_trivial_v && is_standard_layout_v.
I don't see any benefit from is_standard_layout_v,
but I could have missed something.
2021-05-22 18:45:12 +02:00
Bernd Amend
cf7821cb1e fix ChaiScript#537 2021-05-22 18:45:12 +02:00
Bernd Amend
e8e47173fb fix a couple of g++s -Wnoexcept warnings 2021-05-22 18:45:08 +02:00
Bernd Amend
19929be684 don't default implicitly deleted operator=/ctor ChaiScript#527 2021-05-22 18:44:54 +02:00
Bernd Amend
c4e1e1965e remove not required ";" 2021-05-22 14:09:24 +02:00
Bernd Amend
1e6263976f don't return voids 2021-05-22 14:05:52 +02:00
Bernd Amend
2b3bddb02d replace typedef with using 2021-05-22 14:04:04 +02:00
Bernd Amend
684522a8b7 fix -Wcovered-switch-default warnings 2021-05-22 14:01:39 +02:00
Bernd Amend
bd933592a9 hash.hpp: explicitly cast to uint32_t 2021-05-22 13:51:24 +02:00
Bernd Amend
e62f0d3296 drop useless statics and/or add [[nodiscard]] 2021-05-22 13:50:57 +02:00
Bernd Amend
1235fdad7c move ctor arguments into the variables/base class ctors 2021-05-22 13:47:45 +02:00
Bernd Amend
c47b9e3b0d replace const std::string_view with std::string_view 2021-05-22 13:40:32 +02:00
frysch
ab691f687d map_conversion: copy forced for loop var p (incompatible ref type)
The underlying pair that is dereferenced from the iterator has always `const` qualified `first` member (key type). Therefore, an unnecessary temporary was created and bounded to the const ref to the pair. This could be also fixed with `for (const auto &p : from_map)`.
2021-01-15 09:14:49 +01:00
Rob Loach
c7fcc9f7d9
Fix stack_vector.pop_back() pre-decrementing
Fixes #547, found by @balint-luko.
2021-01-07 13:15:47 -05:00
Rob Loach
d7832661e7
Merge pull request #503 from SG-Skril/develop
Fix for lambdas returning booleans

References #481
2020-12-11 14:46:50 -05:00
Glen Fraser
259f130a60 Fix build warnings from unused enums in switch; unused function arg 2020-10-16 11:56:07 +02:00
Glen Fraser
f355d27aea Fix GCC build error "explicit specialization in non-namespace scope"
- other compilers don't complain, but for GCC needed to move the
  template constructor specialization (array of size 0) outside the
  class declaration.
2020-09-04 13:52:25 +02:00
Glen Fraser
350acbf254 Fix compile errors on VS2019 (C++17) with Function_Params
- needed to disambiguate between chaiscript::Function_Params and
  chaiscript::dispatch::detail::Function_Params in several places.
2020-09-04 12:57:49 +02:00
Glen Fraser
4993e4773b Merge branch 'develop' into temp 2020-09-04 11:46:11 +02:00
Glen Fraser
dd69230f19 Fix issues with Function_Params constructors (array and vector args)
- code (on MSVC) was asserting due to trying to dereference invalid
  pointers (dereferencing the end iterator, even if only to get its
  address!).
- when a Function_Params is constructed with an empty vector, you
  can't return the address of the vec.front() -- instead we use
  nullptr for the m_begin and m_end pointers.
2020-09-04 11:27:52 +02:00
Jose Rubio
85e4598986 Fix for warnings: by-copy capture of ‘this’ and unused-local-typedefs
There are two warnings when compiling with GCC 7.4.1 or clang 5.0.1.

   1. warning: explicit by-copy capture of ‘this’ redundant with by-copy capture default
   2. warning: typedef ... locally defined but not used [-Wunused-local-typedefs]

This change removes [2] and it compacts the lambda capture clause in [1].
2020-01-13 16:36:32 +01:00