Scripting Guide

From Trillek Wiki
Jump to: navigation, search

Scripting Reference

This reference is only meant for developers. The Lua features are still WIP and will change in the future.

Lua Implicit Types Registration

All implicit types are expressed as a table in Lua.

The are converted to C++ via:

luaU_check
luaU_to

and to lua via:

luaU_push

Lua Implicit Types

* trillek::physics::Force {x, y, z}
* glm::vec3 {x, y, z}

Lua Method Registration

These are the methods exposed to Lua via luaW_register. The parameters are a string name, global method table, and instance methods.

To add a method to the global table for that type you define:

static luaL_Reg type_table[] =
{{ "Method", Method }, { NULL, NULL }};

Naming doesn't have to be exact but the structure must be.

To add a method that can work on an instance you define:

static luaL_Reg type_metatable[] =
{{ "instanceMethod", InstanceMethod }, { NULL, NULL }};

Naming doesn't have to be exact but the structure must be. InstanceMethod can be a normal function or a class member set via luaU_set, luaU_get, or luaU_getset.

Lua Methods

Physics


* Physics:Get() // Returns a pointer to the physics system of type trillek::physics::PhysicsSystem
* PhysicsSystem:set_force(int entity_id, Force f) // Sets an entity's current linear force to f
* PhysicsSystem:remove_force(int entity_id, Force f) // Removes an entity's current linear force
* PhysicsSystem:set_torque(int entity_id, Torque t) // Sets an entity's current angular force to t
* PhysicsSystem:remove_force(int entity_id, Torque t) // Removes an entity's current angular force
* PhysicsSystem:set_gravity(int entity_id, Force f) // Sets an entity's gravity, pass in nil to return to "world" gravity


Transform


* Transform:Get(int entity_id) // Returns a pointer to the requested entity's trillek::transform
* Transform:set_translation(glm::vec3 amount) // Sets an entity's translation to amount
* Transform:translate(glm::vec3 amount) // Translates an entity by amount
* Transform:set_rotation(glm::vec3 amount) // Sets an entity's rotation to amount
* Transform:rotate(glm::vec3 amount) // Rotates an entity by amount
* Transform:set_scale(glm::vec3 amount) // Sets an entity's scale to amount
* Transform:scale(glm::vec3 amount) // Scales an entity by amount

LuaSys


* LuaSys() // Returns a pointer to the physics system of type trillek::script::LuaSystem
* LuaSys:LoadScriptFile(string filename) // Loads a Lua script from the given filename
* LuaSys:Subscribe(int event_id, string method) // Subscribes to event_id to call method when that event happens