How onitama/openhsp works
Purpose and outputs
OpenHSP is a C/C++ implementation and distribution of the HSP3 scripting language system for building desktop, graphical, game, and utility applications. Its primary product flow is HSP source (.hsp) compiled to an object (.ax) and executed by a selected runtime. Build entry points are makefile, makefile.emscripten, makefile.raspbian, and setup.sh.
User-facing entry points
• Compiler: src/hspcmp/main.cpp drives parsing, symbol management, and code generation into HSP object files.
• Command-line runtime: platform mains such as src/hsp3/linux/main.cpp and src/hsp3/win32/main.cpp host the core interpreter.
• Graphical runtimes: HSP3Dish/HGIMG4 implementations have platform executable entry points including src/hsp3dish/linux/hsp3dish.cpp, src/hsp3dish/win32/main.cpp, and src/hsp3dish/win32gp/main.cpp.
• Editor: Linux editor source is src/tools/linux/hsed_gtk2.cpp; Windows editor variants live under src/tools/win32/hsed3_footy2/.
Core interpreter and object boundary
The portable HSP virtual-machine core is concentrated in src/hsp3/. src/hsp3/hsp3.cpp and src/hsp3/hsp3code.cpp execute compiled instructions; src/hsp3/hsp3int.cpp implements internal operations; typed runtime values are handled by src/hsp3/hspvar_core.cpp plus integer/string/double/label/struct variants. The material boundary is compiled .ax bytecode/object data: compiler output is loaded and interpreted by each runtime rather than linking user scripts into native applications.
Compilation pipeline
src/hspcmp/ is a separate compiler subsystem: lexical/token handling (src/hspcmp/token.cpp), labels and program state (src/hspcmp/label.cpp, src/hspcmp/hsmanager.cpp), command processing (src/hspcmp/hspcmd.cpp), and emission (src/hspcmp/codegen.cpp). It consumes HSP source plus include/module definitions from common/, notably common/hspdef.as, common/hsp3dish.as, and common/hgimg4.as. This shared script-level library layer defines the APIs exposed by runtimes and is a compatibility boundary between authored HSP programs and native implementation.
Runtime specialization and platform boundary
src/hsp3/ supplies base execution, file/package support, system requests, and platform adapters. OS-specific extensions are isolated in src/hsp3/linux/, src/hsp3/win32gui/, src/hsp3/ios/, src/hsp3/ndk/, and src/hsp3/emscripten/. This enables the same bytecode and core semantics across Windows, Linux/Raspberry Pi, Android NDK, iOS, and browser/Emscripten targets, while windows, graphics, I/O, sockets, and native calls remain platform-specific.
HSP3Dish graphics/game stack
src/hsp3dish/ is the graphical runtime layered on the HSP core. Its rendering/window abstraction is represented by src/hsp3dish/hsp3gr_dish.cpp and src/hsp3dish/hspwnd_dish.cpp; sprite support is in src/hsp3dish/essprite.cpp; OBAQ physics integration is in src/hsp3dish/obaq/. Windows has distinct Dish and HGIMG4-oriented builds (src/hsp3dish/win32/, src/hsp3dish/win32gp/). Scripts select these capabilities through includes such as common/hsp3dish.as, common/hgimg4.as, and common/obaq.as.
3D assets and embedded engine dependencies
The repository includes a substantial GamePlay-derived 3D engine under src/hsp3dish/gameplay/src/, covering scenes, models, materials, rendering, animation, input, audio, and physics. Its asset encoder (src/hsp3dish/gameplay/encoder/src/main.cpp, src/hsp3dish/gameplay/encoder/src/FBXSceneEncoder.cpp) converts inputs such as FBX into runtime bundles/GPB assets used by samples. Bundled third-party dependencies include Bullet physics, Lua, OpenAL headers, ANGLE/OpenGL ES support, libpng, zlib, and FreeType under src/hsp3dish/extlib/ and src/hsp3dish/gameplay/encoder/lib/.
External runtime services and distribution content
Linux builds depend on GCC/Make plus OpenGL ES/EGL, SDL2/SDL_mixer, GTK2, libcurl, libgpiod, and libffi. Native extensions/plugins are separate deliverables under src/plugins/, including Windows networking and socket plugins (src/plugins/win32/hspinet/, src/plugins/win32/hspsock/) and Linux extension test code (src/plugins/linux/). sample/ provides executable HSP programs and assets that exercise the compiler-to-runtime path, while doclib_en/ and hsphelp_en/ ship end-user documentation and command help.
Main entry points: hspcmp/main.cpp HSP compiler · makefile Build entry points · hsp3.cpp Instruction execution · linux/main.cpp Command-line runtime
Components 19
Authoring & compilation
- HSP source programs · Authored .hsp programs and sample applications.
- Script API includes · Shared definitions expose runtime capabilities to scripts.
- HSP compiler · Drives parsing, symbols, and object generation.
src/hspcmp/main.cpp - Compiler pipeline · Tokenizes, manages program state, processes commands, and emits code.
- Compiled .ax object · Portable compiled program loaded by runtimes.
- HSP editor
src/tools/linux/hsed_gtk2.cpp
Portable runtime
- HSP VM core · Executes bytecode and provides core runtime semantics.
- Instruction execution
src/hsp3/hsp3.cpp - Typed values · Core and variant implementations for script values.
src/hsp3/hspvar_core.cpp - Platform adapters · Platform-specific windows, I/O, sockets, and native integration.
- Command-line runtime · Hosts the core interpreter for command-line execution.
src/hsp3/linux/main.cpp
Graphics & 3D
- HSP3Dish runtime · Graphical and game runtime layered on the HSP core.
- Dish rendering & windows
src/hsp3dish/hsp3gr_dish.cpp - Sprites & OBAQ physics
src/hsp3dish/essprite.cpp - GamePlay 3D engine · Provides scenes, rendering, animation, input, audio, and physics.
- 3D asset encoder · Converts FBX and other inputs into GPB runtime assets.
src/hsp3dish/gameplay/encoder/src/main.cpp
Delivery & extensions
- Native plugins · Separate platform-specific networking and extension modules.
- Documentation & help
- Build entry points · Makefiles and setup script select native and cross-platform builds.
makefile
Connections 21
- HSP editor → HSP source programs: authors
- HSP source programs → HSP compiler: compiles
- Script API includes → HSP compiler: included by
- HSP compiler → Compiler pipeline: drives
- Compiler pipeline → Compiled .ax object: emits
- Compiled .ax object → HSP VM core: loaded by
- HSP VM core → Instruction execution: executes through
- Instruction execution → Typed values: uses
- Platform adapters → HSP VM core: extends
- Command-line runtime → HSP VM core: hosts
- HSP3Dish runtime → HSP VM core: layers on
- HSP3Dish runtime → Dish rendering & windows: uses
- HSP3Dish runtime → Sprites & OBAQ physics: includes
- HSP3Dish runtime → GamePlay 3D engine: embeds
- 3D asset encoder → GamePlay 3D engine: produces assets for
- Script API includes → HSP3Dish runtime: selects capabilities
- Native plugins → Platform adapters: extend
- Build entry points → HSP compiler: builds
- Build entry points → Command-line runtime: builds
- Build entry points → HSP3Dish runtime: builds
- Documentation & help → HSP source programs: documents