Repository navigation
en scripting overview
中文 | English | Docs | Repository
Nullus ships two scripting backends, C# and Lua. They are not two object models but two language front ends over one native runtime: script component types, instance handles, field access, and lifecycle all go through the same ABI and one shared API manifest.
native scene objects
|
ScriptRuntime (language independent)
|-- IScriptBackend -> CoreCLR (C#)
|-- IScriptBackend -> Lua 5.4 (Lua)
|
ScriptApiDatabase (ScriptApi.json)
|
generated strongly typed C# bindings / reflective Lua bindings
Key constraints:
- There is one language-independent script component type; C# and Lua are not separate component kinds.
-
ScriptApiDatabaseis the only portable contract between native reflection and script bindings. - Member IDs, public names, and both language adapters are generated from the manifest, so no one maintains a second numbering scheme.
- A native ABI version mismatch makes the runtime refuse to load rather than attempt compatibility.
Dropping a .cs or .lua file into the project's Assets/ directory puts it into the asset pipeline:
- Saving
.cstriggers an incremental build and, on success, a hot reload. - Saving
.luatakes effect on reload with no build step. - Both appear in the Asset Browser with their own category icons.
Both languages use the same callback names:
| Callback | When it runs |
|---|---|
Awake |
First entering the running state, once |
Start |
First entering the running state, after Awake, once |
OnEnable |
On every transition from disabled to enabled |
OnDisable |
On every transition from enabled to disabled |
Update |
Every frame |
FixedUpdate |
Fixed-step frames |
LateUpdate |
Every frame, after Update
|
OnDestroy |
On destruction, once |
On the C# side a callback must be an instance method with no parameters returning void and an exact name match; a static method or a same-named method with parameters is not recognized.
Native callback ordering and activation gating are in Lifecycle and Activation.
| Dimension | C# | Lua |
|---|---|---|
| Runtime | CoreCLR | Lua 5.4 |
| Binding | Generated strongly typed bindings | Reflective, lazy bindings |
| Script shape | A class deriving from Nullus.Behaviour
|
A returned module table |
| Iteration | Incremental build and hot reload on save | Reload on save, no build step |
| Debugging | Breakpoints, attach, mixed mode | Optional LuaPanda integration |
| Integer width | 64-bit | 32-bit (LUA_USE_C89) |
Because Lua integers are 32-bit, 64-bit object handles do not cross the script boundary. UI elements are addressed by name, and UICanvasComponent resolves names to handles internally.
using Nullus;
public sealed class ExampleBehaviour : Behaviour
{
private void Awake()
{
Debug.Log($"{name} is ready");
}
private void Update()
{
transform.Rotate(Vector3.up * (30.0f * Time.deltaTime));
}
}Behaviour derives from Component, so gameObject, transform, tag, enabled, and isActiveAndEnabled are directly available.
local Module = {}
function Module:Awake()
Nullus.Debug.Log("ready")
end
function Module:Update()
local position = self.transform.localPosition
position.x = position.x + Nullus.Time.deltaTime
self.transform.localPosition = position
end
return ModuleA script returns a table, the lifecycle functions are members of that table, and the table itself is passed as self. The engine API is exposed through the global Nullus table, for example Nullus.Time and Nullus.Debug.
A script component attaches to a GameObject, and its serializable fields participate in object graph serialization. The generator writes the C# field list into the script manifest, which the editor uses both to draw editable rows in the Inspector and to persist field values when saving a scene.
Fields survive a hot reload where possible: after a successful build the editor swaps to the new assembly at a frame boundary and rebinds. Existing instances only see the backend replacement wrapped in OnDisable and OnEnable; the engine never synthesizes Awake, Start, or OnDestroy.
Files under Assets/**/Editor/**/*.cs belong to the editor assembly, are loaded only in the editor process, and may reference Nullus.Editor to register custom Inspectors, tool windows, and menu items. Player builds exclude them. See Editor Script Extensions.
- No
MonoBehaviourcompatibility type - No coroutines
- The scripting API does not cover physics, audio, or Renderer/Material
- No asset loading API
Adding one of these means extending the API manifest and the native adapters first, then updating both languages' documentation and templates. The order cannot be reversed. See the Scripting API Reference and the Feature Status Matrix.
- Scripting API Reference lists the available types and members.
- Script Debugging and Hot Reload covers breakpoints, attach, and troubleshooting.
Nullus Engine
中文
- 认识 Nullus
- 安装与快速入门
- 使用编辑器
- 场景与对象
- Prefab 工作流
- 资产与内容管线
- 渲染、材质与光照
- 大场景与资源管理
- 游戏逻辑与脚本
- 用户界面
- 动画与角色
- 物理与交互
- 音频、特效与媒体
- AI 与联网
- 平台、构建与发布
- 扩展与引擎架构
- 调试、性能与质量
- 参考手册
- 示例与发展路线
English
- Getting to Know Nullus
- Install and Quick Start
- Using the Editor
- Scenes and Objects
- Prefab Workflow
- Assets and Content Pipeline
- Rendering, Materials, and Lighting
- Large Scenes and Resource Management
- Gameplay and Scripting
- User Interface
- Animation and Characters
- Physics and Interaction
- Audio, Visual Effects, and Media
- AI and Networking
- Platforms, Builds, and Releases
- Extending the Engine
- Debugging, Performance, and Quality
- Reference
- Examples and Roadmap