2427 Commits

Author SHA1 Message Date
leftibot
9680c93bd1
Fix #690: Apply clang-format consistently with CI (#691)
* 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>
2026-04-17 18:45:41 -06:00
leftibot
1cbbba38f9
Fix #116: Add set_file_reader callback for custom file loading (#683)
Add a customizable file reader callback to ChaiScript_Basic, following
the same pattern as set_print_handler. When set, the callback is invoked
instead of the default filesystem read, enabling use cases like encrypted
files, in-memory virtual filesystems, or platform-specific file access
(e.g., Android assets). The callback is settable from both C++ and
ChaiScript.

Co-authored-by: leftibot <leftibot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 16:25:09 -06:00
leftibot
bb06919061
Fix #677: Add strong typedefs (#680)
* Fix #677: Add strong typedefs via 'using Type = BaseType' syntax

Strong typedefs create distinct types backed by Dynamic_Object, so
'using Meters = int' makes Meters a type that is not interchangeable
with int or other typedefs of int. The constructor Meters(val) wraps
the base value, and function dispatch enforces the type distinction.

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

* Address review: add to_underlying function for strong typedefs

Registers a to_underlying() function for each strong typedef that
returns the wrapped base value from the Dynamic_Object's __value attr.

Requested by @lefticus in PR #680 review.

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

* Address review: expose strongly-typed operators for strong typedefs

Register forwarding binary operators at typedef creation time via a
custom Proxy_Function_Base subclass (Strong_Typedef_Binary_Op). Each
operator unwraps __value from both operands, dispatches on the
underlying types, and re-wraps arithmetic results in the typedef.
Comparison operators return the raw bool.

- Arithmetic: +, -, *, /, % → Meters + Meters -> Meters
- Comparison: <, >, <=, >=, ==, != → Meters < Meters -> bool
- Operators that don't exist on the base type error at call time
  (e.g. StrongString * StrongString -> error)
- Users can extend typedefs with their own operations using
  to_underlying() for unwrapping

Tests cover int-based arithmetic, string-based concatenation, string
multiplication error, comparison ops, type safety of results, and
user-defined operator extensions.

Requested by @lefticus in PR #680 review.

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

* Address review: conditionally register operators based on underlying type support

Only register strong typedef operators that actually exist for the
underlying type. Previously all operators were added unconditionally,
causing confusing reflection entries (e.g. * for StrongString) that
would fail at runtime. Now each operator is probed via call_match
against default-constructed base type values before registration.

Also adds bitwise/shift operators (&, |, ^, <<, >>) for types that
support them, and expands test coverage for unsupported operator
rejection.

Requested by @lefticus in PR #680 review.

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

* Address review: register all operators unconditionally and add compound assignment operators

Remove conditional operator registration (op_exists_for_base_type check)
since users could add underlying operators later, and the runtime check was
expensive. Operators that fail on the underlying type now error at call time
instead of being absent. Add compound assignment operators (*=, +=, -=, /=,
%=, <<=, >>=, &=, |=, ^=) via Strong_Typedef_Compound_Assign_Op which
computes the base operation and stores the result back in __value.

Requested by @lefticus in PR #680 review.

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

* Merge upstream/develop into fix/issue-677-add-strong-typedefs

Resolve merge conflicts with ChaiScript:develop. Upstream added
nested namespace support (#675), grammar railroad diagrams (#673),
and WASM exception support (#689). Conflicts in chaiscript_common.hpp,
chaiscript_eval.hpp, and chaiscript_parser.hpp resolved by keeping
both Using and Namespace_Block AST node types.

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

* Address review: add strong typedef documentation to cheatsheet

Add a new "Strong Typedefs" section to the cheatsheet covering:
- Basic usage with `using Type = BaseType` syntax
- Arithmetic and comparison operator forwarding
- String-based strong typedefs
- Accessing the underlying value via to_underlying
- Extending strong typedefs with custom operations

Requested by @lefticus in PR #680 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-15 14:48:49 -06:00
leftibot
1df1b4ad92
Fix #19: Add enum support (#679)
* Fix #19: Add strongly-typed enum support to ChaiScript

Adds the ability to define enums inside ChaiScript with syntax:
  enum Color { Red, Green, Blue }
  enum Priority { Low = 10, Medium = 20, High = 30 }

Enum values are strongly typed Dynamic_Objects accessed via :: syntax
(e.g. Color::Red). A validating constructor from int is registered that
rejects values outside the defined range. Functions declared with an enum
parameter type (e.g. def fun(Color val)) correctly reject plain integers,
enforcing type safety at the dispatch level.

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

* Address review: simplify enum implementation

Remove Enum_Access AST node type — reuse Id_AST_Node for enum value
lookups by combining "EnumName::ValueName" at parse time. Replace
std::set with std::vector for valid value tracking (enums are small).
Net removal of ~18 lines.

Requested by @lefticus in PR #679 review.

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

* Address review: rename to_int to to_underlying, add switch tests

Requested by @lefticus in PR #679 review.

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

* Address review: enum class syntax, constructor, configurable underlying type

- Change syntax from `enum` to `enum class` (only strongly-typed enums)
- Support optional underlying type: `enum class Flags : char { ... }`
  (defaults to `int` when omitted)
- Replace `from_int` with a constructor named after the enum type,
  accessed as `Color::Color(1)` — the underlying type is no longer
  hardcoded to int
- Use Boxed_Number for type-generic value storage and comparison
- to_underlying now returns the actual underlying type

Note: `Color(1)` syntax is not possible because ChaiScript's global
objects shadow functions with the same name; `Color::Color(1)` is the
C++-consistent alternative.

Requested by @lefticus in PR #679 review.

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

* Address review: support enum struct syntax alongside enum class

Requested by @lefticus in PR #679 review.

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

* Address review: update EBNF grammar and cheatsheet with enum documentation

Add enum production rules to the EBNF grammar. Add comprehensive enum
section to the cheatsheet covering syntax, explicit values, underlying
type specification, construction, to_underlying, comparison, type-safe
dispatch, and switch usage. Document that the underlying type must be a
numeric type (string cannot be used) and list all available types.

Requested by @lefticus in PR #679 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-14 22:08:28 -06:00
leftibot
9ff56426e0
Fix #552: Feature-request: nested namespaces (#675)
* Fix #552: Support nested namespaces via dotted names

Namespaces can now be nested using dotted name syntax, both from C++
(register_namespace(gen, "constants.si")) and from script
(namespace("constants.si")). Parent namespaces are auto-registered when
absent, and child namespaces are automatically nested into their parent
on import. This allows clean hierarchical organization like
constants.si.mu_B instead of flat names like constants_si.

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

* Address review: use :: instead of . as nested namespace separator

Switch from dotted names (e.g. "constants.si") to C++-style ::
separator (e.g. "constants::si") for nested namespace declarations,
both in the C++ API (register_namespace) and in script (namespace()).

The original implementation used . because namespace members are
accessed via dot notation at runtime (constants.si.mu_B), making the
declaration separator match the access syntax. However, :: is more
consistent with C++ namespace conventions and aligns with ChaiScript's
existing use of :: for method (def Class::method) and attribute
(attr Class::attr) declarations.

Member access in scripts remains dot-based (constants.si.mu_B) since
that is ChaiScript's member access operator.

Requested by @lefticus in PR #675 review.

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

* Address review: C++-style namespace scoping and block declarations

Add :: scope resolution operator for member access (ns::func works
like ns.func). Add block namespace declarations:
  namespace x::y { def func() { ... } }
Functions and variables declared inside a namespace block are added
as members of the namespace, accessible via :: or dot notation.
Namespaces can be reopened to add more members, matching C++ behavior.

Requested by @lefticus in PR #675 review.

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

* Address review: extract shared make_proxy_function from Def_AST_Node

Namespace_Block_AST_Node was duplicating the entire proxy function
creation logic from Def_AST_Node::eval_internal. Extract a static
make_proxy_function helper so both nodes share the same code path,
eliminating fragile duplication that would drift if Def handling changes.

Requested by @lefticus in PR #675 review.

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

* Address review: reject non-declaration statements inside namespace blocks

Only def, var, auto, and global declarations are now allowed inside
namespace { } blocks. Arbitrary expressions, assignments, and function
calls are rejected with an eval_error. Added compiled tests verifying
that expressions, function calls, and assignments are rejected.

Requested by @lefticus in PR #675 review.

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

* Address review: remove -j parameter from unix builds

Ninja handles parallelism intelligently on its own; the explicit -j flag
was causing memory pressure on sanitizer builds. Windows (non-Ninja)
build retains -j.

Requested by @lefticus in PR #675 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-14 11:49:00 -06:00
leftibot
092ec417d2
Fix #628: Grammar railroad diagram (#673)
* Fix #628: Add EBNF grammar for railroad diagram generation

Add a formal EBNF grammar file (grammar/chaiscript.ebnf) that can be
pasted into rr (https://www.bottlecaps.de/rr/ui) to produce navigable
railroad diagrams of ChaiScript's syntax. The grammar was validated
against the parser implementation and covers all language constructs
including class inheritance, guard conditions, raw strings, and const
declarations that were missing from the original proposal. A reference
section was added to the cheatsheet, and a regression test exercises
every documented grammar construct.

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

* Address review: add grammar railroad diagram link to README

Add a Grammar section to readme.md linking to the EBNF grammar file
and to mingodad's railroad diagram generator for direct viewing.

Requested by @lefticus in PR #673 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-14 10:59:48 -06:00
leftibot
0fd9cab654
Fix #678: Add WASM exception support to Emscripten build (#689)
ChaiScript relies heavily on C++ exceptions for error propagation, but
the Emscripten build was missing the -fwasm-exceptions flag. Without it,
any C++ exception in the WASM module causes an abort instead of being
catchable by JavaScript. Added -fwasm-exceptions as both a compile and
link option, and added a regression test verifying exception propagation
through the eval wrapper functions.

Co-authored-by: leftibot <leftibot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 22:40:26 -06:00
leftibot
e61be76531
Fix #601: Allow operator functions to accept any type with an add() method (#686)
The operator functions in chaiscript::bootstrap::operators (equal, not_equal,
assign, etc.) hardcoded Module& as their first parameter, preventing
chaiscript::utility::add_class for enum types from working when passed a
ChaiScript& reference directly. Added a second template parameter ModuleType
to all operator functions so they accept any type that provides an add()
method, matching the already-templatized add_class functions in utility.hpp.

Co-authored-by: leftibot <leftibot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 20:20:11 -06:00
leftibot
d4c5bdb3e4
Fix #61: Comprehensive exception test suite and fix for silently swallowed exceptions (#681)
When all typed catch blocks failed to match a thrown exception's type,
handle_exception() would silently discard the exception and return a
default-constructed Boxed_Value instead of propagating it. This meant
code like `try { throw(42) } catch(string e) { }` would swallow the
int exception rather than letting it propagate to an outer handler.

The fix adds an explicit re-throw when no catch block matches, and
restructures eval_internal() with a nested try/catch to ensure the
finally block still executes before the unhandled exception propagates.

Co-authored-by: leftibot <leftibot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 19:05:55 -06:00
leftibot
362e93fb29
Fix #499: Add object_from_json, map_to_object, and object_to_map functions (#676)
Add object_from_json as a non-breaking alternative to from_json that returns
a Dynamic_Object instead of a Map, enabling dot-access syntax on JSON fields
(e.g. obj.name instead of obj["name"]). Nested JSON objects become nested
Dynamic_Objects. Also add map_to_object and object_to_map for Python-style
interconversion between maps and objects.

Co-authored-by: leftibot <leftibot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 15:44:04 -06:00
leftibot
07d62aae99
Fix #635: Segfault in async result via dangling pointer from optimized for loop (#671)
* Fix #635: Segfault in async result via dangling pointer from optimized for loop


* The optimized for loop (chaiscript_optimizer.hpp) stored the loop
   counter as a stack-local `int` and exposed it to ChaiScript via
   `var(&i)`, creating a reference-type Boxed_Value pointing to the
   stack frame.
2026-04-12 16:47:06 -06:00
leftibot
5a6050210d
Fix #594: Map keys become dangling references when pushed into Vector (#650)
The Handle_Return_Ref specialization for const references was wrapping
return values in std::cref() while marking them as return values
(is_return_value=true). This caused Vector.push_back() to store the
reference directly without cloning, since it assumes return values are
freshly created temporaries. When the source object (e.g., a map) went
out of scope, the vector contained dangling references to freed memory.

The fix sets is_return_value=false for const reference returns, which
correctly triggers push_back to clone the value instead of storing a
bare reference. This is consistent with the non-const reference handler
(Handle_Return<Ret &>) which also does not set the return value flag.

Co-authored-by: leftibot <leftibot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 16:39:19 -06:00
leftibot
9237acbbb9
Fix #634: Add divide-by-zero check for modulo assignment operator (#672)
The assign_remainder (%=) case in Boxed_Number::go was missing the
check_divide_by_zero guard, causing a hardware SIGFPE on integer
modulo by zero. Also moved a misplaced check_divide_by_zero from
assign_bitwise_and (&=) where it was erroneous. Additionally, the
catch block in Equation_AST_Node::eval_internal was masking the
arithmetic_error exception as a generic "unsupported operation" error;
arithmetic_error is now re-thrown to provide the correct error message.

Co-authored-by: leftibot <leftibot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 16:28:41 -06:00
leftibot
4804fb6e03
Fix #666: TSAN builds don't actually use threads (#670)
* Fix #666: TSAN builds don't actually use threads

TSAN builds did not explicitly enable MULTITHREAD_SUPPORT_ENABLED, so they
relied on the CMake default. This adds -DMULTITHREAD_SUPPORT_ENABLED=ON to
both TSAN jobs and expands the CI matrix to cover threading on/off with
Debug/Release for Linux, macOS, and Windows MSVC. Also excludes async-dependent
.chai tests from non-threaded builds and adds a Threading_Config_Test to verify
the threading configuration is correct in both modes.

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

* Address review: use Ninja generator for all unix CI targets

Requested by @lefticus in PR #670 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 20:25:46 -06:00
leftibot
726169acc8
Fix #398: Allow overriding [] operator with string index on Dynamic_Object subtypes (#667)
The built-in Dynamic_Object::get_attr was always winning dispatch over
user-defined [] overrides when a string index was used, because its C++
type signature (Dynamic_Object, const string&) scored numdiffs=0 while
ChaiScript-defined functions had higher numdiffs due to undefined type
info. The fix deprioritizes generic C++ Dynamic_Object functions when the
actual first argument is a specific subtype, and maps named ChaiScript
type parameters to Dynamic_Object type_info for correct dispatch scoring.

Co-authored-by: leftibot <leftibot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 18:59:09 -06:00
leftibot
bcd07e05cd
Fix #571: How to redirect "cout" and "print" to a microsoft Windows 10 window? (#657)
* Fix #571: Add per-instance IO redirection via set_print_handler/set_println_handler

The print_string and println_string functions were previously registered as static
functions writing directly to stdout, making it impossible to redirect ChaiScript
output to custom destinations (e.g., GUI windows, loggers, or buffers). This moves
their registration from Bootstrap::bootstrap() to ChaiScript_Basic::build_eval_system()
as lambdas that dispatch through configurable std::function handlers, allowing each
ChaiScript instance to independently redirect its output via set_print_handler() and
set_println_handler().

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

* Address review: add IO redirection section to cheatsheet

Documents set_print_handler() and set_println_handler() with usage
examples for GUI embedding and output capture.

Requested by @lefticus in PR #657 review.

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

* Address review: define println in terms of print, expose set_print_handler to ChaiScript

Remove separate println_handler — println_string now dispatches through the
single print handler with a newline appended. Only set_print_handler is
needed to redirect all output. The set_print_handler function is also
registered in the ChaiScript engine, so scripts can capture and redirect
their own output.

Requested by @lefticus in PR #657 review.

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

* Address review: populate null print handler when No_IO is set

When No_IO is active, the default m_print_handler is now a no-op instead
of writing to stdout. The stdout handler is only installed when No_IO is
not set. Users can still override the handler via set_print_handler()
even with No_IO enabled.

Requested by @lefticus in PR #657 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 18:58:09 -06:00
leftibot
dcdab50efd
Fix #470: Expose find() for associative container types (#668)
Add a native find() method to unique associative containers (e.g., Map)
that returns the mapped value if the key exists, or an undefined
Boxed_Value if not. This allows checking for key existence without
mutating the container (unlike operator[]) or requiring exception
handling (unlike at()).

Co-authored-by: leftibot <leftibot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 18:57:26 -06:00
leftibot
0d1ceed05d
Fix #473: Allow assignment expressions in return statements (#665)
The Return() parser function called Operator() to parse the return value,
which only handles arithmetic/logical operators but not assignments. Changed
it to call Equation(), which wraps Operator() and adds assignment parsing.
This is consistent with how If, For, and function argument parsing already
work. Enables `return foo = 5`, `return x += 1`, etc.

Co-authored-by: leftibot <leftibot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 17:13:50 -06:00
leftibot
08281a9d69
Fix #146: Add configuration to bypass the registering of 'built-in' functions. (#642)
* Fix #146: Add configuration options to selectively disable built-in functions

Add new Options enum values (No_Stdlib, No_IO, No_Prelude, No_JSON) that
allow users to control which parts of the standard library are registered.
Std_Lib::library() now accepts an options vector, and the ChaiScript
convenience class forwards its options to the library builder. This enables
use cases where only custom functions should be exposed to script users.

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

* Address review: split Options into Options and Library_Options enums

Separate system-level options (No_Load_Modules, Load_Modules, No_External_Scripts,
External_Scripts) from library-level options (No_Stdlib, No_IO, No_Prelude, No_JSON)
into two distinct enum types. Add Library_Options as a parameter to the ChaiScript
constructor. Update tests to demonstrate both ChaiScript_Basic (explicit Std_Lib::library
call) and ChaiScript (library options via constructor parameter) usage.

Requested by @lefticus in PR #642 review.

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

* Add cheatsheet documentation for Options and Library_Options

Documents the two-enum configuration system: Options (engine-level:
load_module, use, eval_file) and Library_Options (stdlib-level:
No_Stdlib, No_IO, No_Prelude, No_JSON), with usage examples for
both ChaiScript and ChaiScript_Basic constructors.

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 16:49:13 -06:00
leftibot
005f18feb2
Fix #524: Support std::vector of non-copyable types like std::unique_ptr (#648)
Several STL bootstrap functions unconditionally instantiated copy-dependent
operations (copy constructor, assignment, push_back/push_front by const ref,
insert_at, and resize with fill value), causing compilation failures when
registering containers of move-only types like std::unique_ptr. Guard these
operations with if constexpr(std::is_copy_constructible_v<value_type>) so they
are only compiled when the element type supports copying.

Co-authored-by: leftibot <leftibot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Jason Turner <jason@emptycrate.com>
2026-04-11 16:44:06 -06:00
leftibot
11fec25112
Fix #625: function_less_than comparator violates strict-weak ordering (#654)
The function_less_than comparator used by std::stable_sort violated the
strict-weak ordering requirement in two ways: (1) functions with different
arities but matching overlapping parameters were treated as equivalent,
breaking transitivity, and (2) the dynamic_object_type_name comparison
silently fell through when one side had an empty type name. Fixed by
ordering by arity when overlapping parameters match, and imposing a total
order on dynamic object type names.

Co-authored-by: leftibot <leftibot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Jason Turner <jason@emptycrate.com>
2026-04-11 16:42:40 -06:00
leftibot
7b95ff5126
Fix #655: Async issues with threads outliving the chaiscript engine (#656)
* Fix #655: Join async threads before engine destruction to prevent heap-use-after-free

Issues #632 and #636 (PRs #651 and #653) both stem from the same root cause: async
threads spawned via async() can outlive the Dispatch_Engine, accessing shared state
(global objects map, type maps) after it has been destroyed. The fix moves async()
registration from the stdlib module into ChaiScript_Basic, where spawned threads are
tracked via Dispatch_Engine. The engine's destructor now joins all outstanding async
threads before destroying shared data structures.

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

* Address review: follow rule of 5, explicitly default move operations

Requested by @lefticus in PR #656 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 16:12:41 -06:00
leftibot
1b27d0dd15
Fix #459: Fill out the set of conversion functions for all POD types (#664)
Previously, to_<type> only accepted a string or the same type (identity),
and <type>() constructors only accepted Boxed_Number. This left gaps such as
to_int(char), to_char(int), char(string), int(string), and to_double(char).

Add two overloads to bootstrap_pod_type: to_<name>(Boxed_Number) enables
cross-type numeric conversions (e.g. to_int('A') → 65, to_char(65) → 'A'),
and <name>(string) via parse_string enables construction from strings
(e.g. char("A") → 'A', int("65") → 65, double("3.5") → 3.5).

Co-authored-by: leftibot <leftibot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 16:08:09 -06:00
leftibot
340e7d4b16
Fix #472: Emscripten Frontend (#662)
* Fix #472: Add Emscripten/WebAssembly build for browser-based ChaiScript

Port Rob Loach's ChaiScript.js work (https://github.com/RobLoach/ChaiScript.js)
into the main repository as an Emscripten build target. Adds a GitHub Actions
workflow that builds ChaiScript to WebAssembly and publishes artifacts (JS, WASM,
HTML) for embedding in the official ChaiScript.com website. Includes an HTML
interactive playground frontend and a native test validating the eval API surface.

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

* Address review: publish WASM assets as release under wasm-latest tag

Add a publish job to the emscripten workflow that creates a prerelease
tagged wasm-latest with chaiscript.js, chaiscript.wasm, and
chaiscript.html as downloadable assets. Runs only on pushes to the
develop branch. The website repo can fetch these via the public
GitHub Releases API on a daily cron without any cross-repo auth.

Requested by @lefticus in PR #662 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: Rob Loach <robloach@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
wasm-latest
2026-04-11 15:58:28 -06:00
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
bc771ab8ba
[WIP] Issue #615 — Switch to GitHub Actions (#658)
* Fix #615: Switch from Travis CI to GitHub Actions

Add a GitHub Actions CI workflow with a full build matrix covering
linux, macOS, and Windows with both GCC and Clang compilers, Debug
and Release build types, and optional ASan+UBSan sanitizers (24 builds
total). Windows builds use MSYS2 for GCC/Clang toolchains. The workflow
relies on CMake and CTest to drive configuration, building, and testing.

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

* Address review: use native compilers, remove MSYS/MinGW

Use Visual Studio (MSVC) on Windows, Apple Clang on macOS, and GCC on
Linux. Remove MSYS2/MinGW toolchain setup entirely. Split into three
separate jobs for clarity. Fix workflow validation issues.

Requested by @lefticus in PR #658 review.

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

* Address review: add workflow_dispatch to enable manual CI runs on fork

Add workflow_dispatch trigger so the workflow can be manually run on the
leftibot fork to verify that GitHub Actions are working correctly.

Requested by @lefticus in PR #658 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 13:40:04 -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
Jason Turner
f1ab992d0a
Merge pull request #645 from leftibot/fix/issue-477-json-unicode-escape
Fix #477: Handle \u unicode escape in JSON parser
2026-04-10 21:58:07 -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
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
Jason Turner
22092656fd
Merge pull request #644 from leftibot/fix/issue-421-switch-type-conversion
Fix #421: Switch with type_conversion compares destroyed objects
2026-04-10 18:36: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
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
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
Jason Turner
2e2740f90d
Merge pull request #637 from leftibot/fix/issue-12-document-reflection
[WIP] Issue #12 — Document reflection
2026-04-10 17:41:13 -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
2eb3279c39
Merge pull request #630 from ChaiScript/update-catch
Update catch.hpp to v2.13.9
2025-07-30 17:07:44 -04:00
Rob Loach
2951ce4a7a
Update catch.hpp to v2.13.9
Fixes #619
2025-07-28 09:33:41 -04:00
Rob Loach
f904cd5447
Merge pull request #626 from CTerasa-ep/fix-warnings
Fix several `noexcept` and `possibly dangling reference` warnings
2025-02-20 09:45:10 -05:00