Skip to content

About

Header-only C++20 library that writes the API registered in a running AngelScript engine to a .as.predefined stub for AngelLSP and angelscript-mcp.

Topics

Resources

Contributing

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

AngelScript API Dumper

English | Español

CI License: MIT

A header-only C++20 library that inspects a running asIScriptEngine* and writes every type, method, property, funcdef, typedef, enum, and global registered by the host into a .as.predefined stub for AngelLSP and angelscript-mcp. Language servers and AI agents need to know the exact host API so semantic analysis, diagnostics, and completion resolve symbols without a live engine; hand-written stubs inevitably drift from what the engine actually accepts, whereas walking the engine's registration tables directly guarantees ground truth without manual maintenance. Internal symbols containing $ (such as synthetic compiler behaviours and $list factories) and template-nested funcdefs (such as array<T>::less) are skipped so the emitted stub remains valid AngelScript syntax. Reference-type factories are not listed; see Compatibility.

Use

Copy include/angelscript-api-dumper/api_dumper.hpp into your project, or add this repository as a CMake subdirectory:

add_subdirectory(external/angelscript-api-dumper)
target_link_libraries(my_host PRIVATE angelscript-api-dumper::angelscript-api-dumper)

Include the header and dump the engine after registering your host API:

#include <angelscript-api-dumper/api_dumper.hpp>
#include <cstdio>

void ExportStub(asIScriptEngine* engine)
{
    as_api_dumper::Dump(engine, stdout);
}

Build and run the tests

git clone https://github.com/angelscript-tools/angelscript-api-dumper.git
cd angelscript-api-dumper
git submodule update --init
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build build
ctest --test-dir build --output-on-failure

When -DANGELSCRIPT_SDK=<path> is omitted, CMake prepares AngelScript 2.39.0 via external/angelscript-engine/scripts/prepare-sdk.py and builds it with external/angelscript-engine/cmake/AngelScriptEngine.cmake.

API

All symbols live in namespace as_api_dumper inside include/angelscript-api-dumper/api_dumper.hpp, with no global state, no escaping exceptions, and no dependency beyond <angelscript.h> and the C++20 standard library.

Symbol Purpose
struct Baseline Stores counts of enums, typedefs, funcdefs, object types, global properties, and global functions to skip.
enum class Alignment Selects spacing around & and @: AsRegistered, Left, Right, or Middle.
struct DumpOptions Configures indentation, brace placement, trailing blank line, and reference/handle alignment.
Baseline Capture(asIScriptEngine* engine) Records current registration counts so a later Dump emits only subsequent registrations (for example, skipping standard add-ons).
void Dump(asIScriptEngine* engine, std::FILE* out, const Baseline& baseline = {}) Emits the .as.predefined stub to a std::FILE* stream with default options.
void Dump(asIScriptEngine* engine, std::FILE* out, const Baseline& baseline, const DumpOptions& options) Emits the .as.predefined stub to a std::FILE* stream using custom DumpOptions.
void Dump(asIScriptEngine* engine, std::ostream& out, const Baseline& baseline = {}) Emits the .as.predefined stub to a std::ostream with default options.
void Dump(asIScriptEngine* engine, std::ostream& out, const Baseline& baseline, const DumpOptions& options) Emits the .as.predefined stub to a std::ostream using custom DumpOptions.
RegisterStdString(engine);
RegisterScriptArray(engine, true);

// Skip the standard add-ons and dump only host-specific registrations.
const as_api_dumper::Baseline baseline = as_api_dumper::Capture(engine);
RegisterGameApi(engine);

std::ofstream out("game.as.predefined", std::ios::binary);
as_api_dumper::Dump(engine, out, baseline);

Layout options

Pass a DumpOptions value to the four-argument Dump overload to match a project's .clang-format layout instead of post-processing the stub. Default options keep the original output byte-identical.

DumpOptions field Default .clang-format key Notes
useTab false UseTab Indent with \t per level instead of spaces.
indentWidth 4 IndentWidth / TabWidth Spaces per level when useTab is false (0 is treated as 4).
braceOnNewLine true BreakBeforeBraces Allman (true, { on its own line) vs Attach (false, namespace x {, class X {, enum E {).
trailingBlankLine true MaxEmptyLinesToKeep true keeps the trailing blank line at EOF; false ends with a single \n. AngelLSP removes trailing newlines through its own trimFinalNewlines option (default true), so reproducing true there also needs trimFinalNewlines: false.
referenceAlignment Alignment::AsRegistered ReferenceAlignment Rewrites & spacing (AsRegistered, Left, Right, Middle).
pointerAlignment Alignment::AsRegistered PointerAlignment Rewrites @ spacing (AsRegistered, Left, Right, Middle); @+ stays untouched.
as_api_dumper::DumpOptions options;
options.indentWidth = 2;
options.braceOnNewLine = false;
options.trailingBlankLine = false;
options.referenceAlignment = as_api_dumper::Alignment::Left;
options.pointerAlignment = as_api_dumper::Alignment::Left;

std::ofstream out("game.as.predefined", std::ios::binary);
as_api_dumper::Dump(engine, out, baseline, options);

Compatibility

From reading angelscript.h and changes2.html in the AngelScript 2.39.0 SDK alongside angelscript-engine/docs/ENGINE_VERSIONS.md: asITypeInfo was introduced in 2.31.0, and asITypeInfo::GetUnderlyingTypeId() was added in 2.39.0 (deprecating GetTypedefTypeId()). Releases older than 2.39.0 use #if ANGELSCRIPT_VERSION >= 23900 to fall back to GetTypedefTypeId(). The releases listed as yes below were built and tested; the rest are marked unverified until CI measures them.

AngelScript Supported Note
2.39.0 yes Built and tested: MSVC 19.5 x64 Release with /W4 /WX. Uses asITypeInfo::GetUnderlyingTypeId() and 64-bit enum values.
2.38.0, 2.37.0, 2.36.1, 2.35.1, 2.33.0, 2.31.0 yes Each built and tested the same way. Falls back to asITypeInfo::GetTypedefTypeId() and int enum values (ANGELSCRIPT_VERSION < 23900).
2.31.1 – 2.32.0, 2.33.1 – 2.35.0, 2.36.0 unverified Not built; the headers of the releases around them are covered above.
2.30.2 and earlier no No asITypeInfo. Export with AngelScript's WriteConfigToFile (add_on/scripthelper) and convert with angel_lsp --convert-config <as_config.txt> [output.as.predefined].

Reference types registered with a factory (asBEHAVE_FACTORY) are listed with their methods and properties but without a constructor line: the dumper reads behaviours through GetBehaviourByIndex, which does not return factories. angelscript --dump-predefined in angelscript-cli 1.4 has the same output, and the dumper keeps it byte for byte.

Contributing

Read CONTRIBUTING.md before opening a pull request. tests/golden/host.as.predefined, tests/golden/host.left.as.predefined, and tests/golden/host.attach.as.predefined are generated by the test host (angelscript_api_dumper_tests --dump <path> [--layout left|attach]); regenerate and diff them rather than editing them by hand.

Related

Project Use
angelscript-lsp Language server and VS Code extension consuming .as.predefined stubs
angelscript-mcp MCP server for AI agents working with AngelScript
angelscript-cli Standalone AngelScript CLI (asc --dump-predefined)
angelscript-engine Pinned and patched SDK builds for AngelScript 2.20 to 2.39
angelscript-agent-kit Skill and one-step installs for Claude Code, Codex, Gemini CLI and Antigravity
angelscript-dap Debugger core (Debug Adapter Protocol)
angelscript-debugger-example A host that shows how to use the debugger
angelscript-jit Optional JIT compiler
tree-sitter-angelscript Tree-sitter grammar the language server uses

License

This repository is licensed under the MIT License.

About

Header-only C++20 library that writes the API registered in a running AngelScript engine to a .as.predefined stub for AngelLSP and angelscript-mcp.

Topics

Resources

Contributing

Stars

2 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages