Create an early scripting engine #2
No reviewers
Labels
No Label
Kind/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: SeanOMik/lyra-engine#2
Loading…
Reference in New Issue
No description provided.
Delete Branch "feature/early-scripting"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This pr adds a working Lua scripting engine. The engine is capable of reloading the scripts on a change, loading 3d models, spawning entities, moving them around, and even responding to keyboard input. Not everything is exposed to Lua yet, I need to figure out some easier ways to do it since currently its a massive pain and completely manual.
To be able to support scripts, other features were added to other crates, like asset change watching, and staged system execution, among many other things that I didn't keep track of. I tried to use
mlua
as the Lua library, but found it limiting so ended up just making my own:elua
(short for "easy lua").Loading a Lua script:
Every system tick the scripts will be executed. The scripting engine loads the Lua script and looks for functions in it with the name of
on_<stage>
, and will execute those functions on the ECS stage. The stages that are built into the engine are already supported by the scripting engine. So the function names in order of execution are,on_init
,on_first
,on_pre_update
,on_update
,on_post_update
,on_last
.On the execution of each script, globals are set so the programmer can make changes to the world. The ECS world is exposed as
world
, and the entity that the script is on is exposed asentity
.Brief overview of World
Exposed methods:
request_res
: Used to request assets.add_resource
: Used to add a resource to the ECS world.resource
: Used to get resources from the ECS world.view
: Used to view into the ECS world and query for components.system: Function(...comps) -> ...comps, ...comps
Brief overview of Scripting Engine
The scripting engine exposes APIs through "Providers". The providers can register types to Lua. These types can be wrappers of Rust types (e.g.,
LuaModelComponent
,LuaActionHandler
, etc.), be converted to and from Lua types (e.g.,LuaDeltaTime
), or converted to and from Lua tables (no types use this currently, it was discovered to be slower than wrapped types). View the extension traitRegisterLuaType
for World to see all the ways that types can be exposed to Lua.