Complete API reference for the HoloScript core package.
npm install @holoscript/core
# or
pnpm add @holoscript/coreimport { HoloParser, parseHolo, compile } from '@holoscript/core';
// Parse a .holo file
const result = parseHolo(`
composition "MyScene" {
object "Cube" {
geometry: "cube"
position: [0, 1, 0]
}
}
`);
// Compile to target platform
const output = compile(result.composition, { target: 'threejs' });Main parser for .holo composition files.
import { HoloParser } from '@holoscript/core';
const parser = new HoloParser();
const result = parser.parse(source);
if (result.success) {
console.log(result.composition);
} else {
console.error(result.errors);
}| Method | Parameters | Returns | Description |
|---|---|---|---|
parse(source) |
string |
HoloParseResult |
Parse .holo source code |
parseStrict(source) |
string |
HoloParseResult |
Parse with strict validation |
Convenience function for parsing .holo files.
import { parseHolo } from '@holoscript/core';
const { success, composition, errors } = parseHolo(source);Parser for .hsplus files with VR traits.
import { HoloScriptPlusParser } from '@holoscript/core';
const parser = new HoloScriptPlusParser();
const result = parser.parse(`
composition Player {
@grabbable
@physics(mass: 2.0)
position: [0, 1.6, 0]
}
`);Legacy parser for .hs files.
import { HoloScriptParser } from '@holoscript/core';
const parser = new HoloScriptParser();
const ast = parser.parse(source);Compile a HoloComposition to a target platform.
import { compile } from '@holoscript/core';
const output = compile(composition, {
target: 'threejs', // | 'unity' | 'vrchat' | 'unreal' | etc.
optimize: true,
minify: false,
});| Option | Type | Default | Description |
|---|---|---|---|
target |
CompileTarget |
'threejs' |
Target platform |
optimize |
boolean |
true |
Enable optimizations |
minify |
boolean |
false |
Minify output |
sourceMap |
boolean |
false |
Generate source map |
type CompileTarget =
| 'threejs'
| 'babylon'
| 'aframe'
| 'webxr'
| 'webgpu'
| 'unity'
| 'unreal'
| 'godot'
| 'vrchat'
| 'openxr'
| 'visionos'
| 'ios'
| 'android'
| 'androidxr'
| 'wasm'
| 'urdf'
| 'sdf'
| 'dtdl';import { VRChatCompiler, UnrealCompiler, IOSCompiler, AndroidCompiler } from '@holoscript/core';
const compiler = new VRChatCompiler();
const output = compiler.compile(composition);Execute HoloScript in browser or Node.js.
import { HoloScriptRuntime } from '@holoscript/core';
const runtime = new HoloScriptRuntime(ast);
await runtime.mount(document.getElementById('canvas'));
// Control runtime
runtime.play();
runtime.pause();
runtime.dispose();| Method | Description |
|---|---|
mount(element) |
Mount to DOM element |
play() |
Start execution |
pause() |
Pause execution |
reset() |
Reset to initial state |
dispose() |
Clean up resources |
getObject(name) |
Get object by name |
setState(key, value) |
Update state |
getState(key) |
Get state value |
Factory function for runtime creation.
import { createRuntime } from '@holoscript/core';
const runtime = createRuntime(composition, {
renderer: 'webgl',
physics: true,
audio: true,
});Root type for .holo files.
interface HoloComposition {
name: string;
environment?: HoloEnvironment;
templates?: HoloTemplate[];
objects?: HoloObjectDecl[];
spatialGroups?: HoloSpatialGroup[];
lights?: HoloLight[];
cameras?: HoloCamera[];
state?: HoloState;
actions?: HoloAction[];
logic?: HoloLogic;
audio?: HoloAudio[];
ui?: HoloUI[];
}Object declaration.
interface HoloObjectDecl {
name: string;
template?: string; // "using Template"
traits?: HoloObjectTrait[]; // @grabbable, @physics, etc.
properties: Record<string, HoloValue>;
children?: HoloObjectDecl[];
}Reusable object template.
interface HoloTemplate {
name: string;
traits?: HoloObjectTrait[];
properties: Record<string, HoloValue>;
state?: Record<string, HoloValue>;
actions?: HoloAction[];
eventHandlers?: HoloEventHandler[];
}Result from parsing operations.
interface HoloParseResult {
success: boolean;
composition?: HoloComposition;
errors: HoloParseError[];
warnings: HoloParseError[];
}Error from parsing.
interface HoloParseError {
code: string;
message: string;
line: number;
column: number;
suggestion?: string;
}Validate HoloScript code.
import { HoloScriptValidator } from '@holoscript/core';
const validator = new HoloScriptValidator();
const errors = validator.validate(ast);Validate VR trait usage.
import { validateTrait, TRAIT_DEFINITIONS } from '@holoscript/core';
const errors = validateTrait('@grabbable', parameters);Format errors for display.
import { formatRichError } from '@holoscript/core';
const formatted = formatRichError(error, source);
console.log(formatted);
// → Error: Unknown trait @grababble
// Did you mean: @grabbable?
// at line 5, column 3Get source code context around an error.
import { getSourceContext } from '@holoscript/core';
const context = getSourceContext(source, line, column);
// Returns surrounding lines with pointerimport { GEOMETRY_TYPES } from '@holoscript/core';
// ['cube', 'sphere', 'cylinder', 'cone', 'torus', 'plane', 'capsule', ...]import { EVENT_NAMES } from '@holoscript/core';
// ['onGrab', 'onRelease', 'onClick', 'onHoverEnter', 'onHoverExit', ...]import { EASING_FUNCTIONS } from '@holoscript/core';
// ['linear', 'easeIn', 'easeOut', 'easeInOut', 'bounce', 'elastic', ...]