505 Commits

Author SHA1 Message Date
leftibot
255ff87f37
Fix #405: push_back() on script-created vector has no effect if vector_conversion is in effect (#663)
* Fix #405: push_back() on script-created vector has no effect with vector_conversion

When both vector_type<T> and vector_conversion<T> are registered, the
dispatch scoring treats all parameter mismatches equally. This causes
the C++ push_back (for the converted type) to be selected over the
built-in one when both have the same number of type differences. The
converted function operates on a temporary copy of the vector, silently
discarding the mutation. The fix deprioritizes overloads that require
type conversion on the first parameter (the object/receiver), ensuring
functions matching the receiver type exactly are always tried first.

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

* Address review: remove issue references from comments, add round-trip conversion tests

Requested by @lefticus in PR #663 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 15:45:22 -06:00
leftibot
92abd226a9
Fix #660: Windows builds are broken (#661)
* Fix #660: Fix Windows builds, remove Appveyor, add sanitizer CI builds

Add missing #include <chrono> to src/main.cpp which caused MSVC build
failures since high_resolution_clock and duration_cast were used without
the header (GCC/Clang included it transitively). Remove obsolete
appveyor.yml (superseded by GitHub Actions). Add ASAN+UBSAN build
jobs for Linux and macOS in the CI workflow.

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

* Address review: add Windows ASAN+UBSAN sanitizer support

- Add MSVC-native ASAN support in CMakeLists.txt (/fsanitize=address)
  with /RTC removal and /INCREMENTAL:NO (both incompatible with ASAN)
- Add Windows MSVC ASAN CI job
- Add Windows ClangCL ASAN+UBSAN CI job (UBSAN requires Clang, not
  available in native MSVC)
- Fix sanitizer guard to include AppleClang (macOS sanitizer jobs were
  silently not enabling sanitizers)

Requested by @lefticus in PR #661 review.

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

* Address review: remove Windows sanitizers, add TSAN for Linux/macOS

Remove windows-sanitizers and windows-clangcl-sanitizers CI jobs.
Add linux-tsan and macos-tsan CI jobs using ENABLE_THREAD_SANITIZER.

Requested by @lefticus in PR #661 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 15:06:33 -06:00
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
fa4b8277f5
Fix #554: Document the difference between add, add_global, and set_global (#649)
Updated the cheatsheet to clearly explain that `add` creates thread-local
scoped variables while `add_global`, `add_global_const`, and `set_global`
create global variables shared between all threads. Added a summary table
comparing scope, thread safety, and conflict behavior. Also added a test
exercising the key behavioral differences between these methods.

Co-authored-by: leftibot <leftibot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 11:17:46 -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
leftibot
91e50bc80f Add tests for JSON \u unicode escape sequences
Tests cover ASCII range, 2-byte UTF-8 (U+00C4), 3-byte UTF-8 (U+20AC),
mixed text, multiple escapes, uppercase hex, and unicode in object values.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 19:49:56 -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
leftibot
a329be16ad Add tests for #421: switch with type_conversion lifetime bug
Add both a compiled C++ test (with registered type_conversion) and a
pure ChaiScript test (with dynamic objects and custom == operator) to
verify that switch case comparisons properly manage object lifetimes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 18:18:25 -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
Jason Turner
cb48b7cc7e
Merge pull request #639 from leftibot/fix/issue-591-classes
[WIP] Issue #591 — Classes?
2026-04-10 17:57:29 -06:00
leftibot
25c520ed81 Address review: remove issue number references from code
Requested by @lefticus in PR #639 review.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 11:31:59 -06:00
leftibot
28894373f7 Fix #591: Add comprehensive class definition docs to cheatsheet
The cheatsheet's "ChaiScript Defined Types" section was minimal, showing only
a basic class with one attribute and a getter. Expanded it to document block
syntax, open syntax, attribute keywords (var/attr/auto), constructor and method
guards, operator overloading, cloning, and added a test exercising all examples.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 22:15:47 -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
Rob Loach
2951ce4a7a
Update catch.hpp to v2.13.9
Fixes #619
2025-07-28 09:33:41 -04: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
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
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
55ec76fd39 fix testcase "Test unicode matches C++" 2021-05-22 23:54:18 +02:00
Bernd Amend
cf7821cb1e fix ChaiScript#537 2021-05-22 18:45:12 +02:00
Bernd Amend
5ff3679811 fix u8"" compilation error in g++11 with -std=c++20 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
c4e1e1965e remove not required ";" 2021-05-22 14:09:24 +02:00
Bernd Amend
2b3bddb02d replace typedef with using 2021-05-22 14:04:04 +02:00
Bernd Amend
c26fd14953 remove else after return 2021-05-22 13:55:04 +02:00
Bernd Amend
180a6d4a1c update catch to version 2.13.6 2021-05-22 13:18:49 +02:00
Bernd Amend
52a9fa47c1 replace std::vector::push_back with emplace_back 2021-05-22 13:18:32 +02:00
draghan
0a3bc48788 Add unit test covering issue #481
Implemented unit test which is validating whether a lambda from
Chaiscript could return a boolean value without throwing any exception.

The same test case is checking whether lambda with boolean return value
could be called peacefully from Chaiscript.
2021-03-27 21:17:55 +01:00
Glen Fraser
cb9a8587b6 Remove MSVC special case in 'Object copy counts' unit test 2020-09-04 11:45:08 +02:00
Jason Turner
c737f2419b
Merge pull request #453 from AlekMosingiewicz/error_on_double_conversion
Error on double conversion
2018-08-15 13:33:13 -06:00
Jason Turner
5db87a9175 Merge branch 'release-6.x' into develop 2018-08-15 13:13:44 -06:00
Jason Turner
44dab4d45c Deal with returning of & to * types 2018-08-15 13:10:23 -06:00
Jason Turner
4be5e876b8 Add failing test for returning of & to * 2018-08-15 11:19:09 -06:00
Alek Mosingiewicz
a254e11286 Make information on source and target types in Type Conversion
Exception public.
2018-08-13 17:57:38 +02:00
Alek Mosingiewicz
27bee4a266 Bypass the mutex problem when looking for conversion, automatic
test.
2018-08-10 17:29:46 +02:00
Jason Turner
07fdb3bf6e Remove backward compatibility tests 2018-06-03 16:48:03 -06:00
Jason Turner
d0d08d2ed9 Merge branch 'best_practices' into develop 2018-06-03 16:40:29 -06:00
Jason Turner
aa61df941b
Merge pull request #420 from StanEpp/c++17
Add support for chained dot calls.
2018-06-03 15:47:05 -06:00
Jason Turner
a880319db8 Merge branch 'develop' into best_practices 2018-05-30 08:30:29 -06:00
Jason Turner
d5d5561d74 Add failing test for lifetime with ranged-for loop
References: #392
2018-05-29 08:03:59 -06:00
Jason Turner
98c362d038 Properly report which file failed to be loaded
closes #437
2018-05-29 07:45:43 -06:00
Jason Turner
61dfb22af8
Merge pull request #439 from AlekMosingiewicz/handle-bom-in-script
Handle BOM in the beginning of the script
2018-05-26 14:08:29 -06:00
Jason Turner
73f177c73e Move to official catch cmake support, update catch
This is an effort to fix the issues on Appveyor with newer versions of
CMake. Will have to double check that it does not break Travis
2018-05-26 09:26:13 -06:00
Jason Turner
805e7c0917 Fix up some error handling 2018-05-25 14:33:17 -06:00
Alek Mosingiewicz
67dcd3e8d8 Test case for BOM in user-provided string. 2018-05-22 17:12:14 +02:00