allow luaget/luaset/luacall to access tables and methods, improve type conversion, add bl.string, begin adding matrix
This commit is contained in:
30
readme.md
30
readme.md
@@ -36,6 +36,8 @@ Lua scripting for Blockland
|
||||
`object:method(args)` - Call a Torque object method
|
||||
`object[index]` - Access a member of a Torque set or group
|
||||
`for childIndex, child in object:members() do` - Iterate objects within of a Torque set or group. Indices start at 0 like in Torque.
|
||||
`bl.isObject(object, objectID, or 'objectName')` - Check if an object exists
|
||||
`object:exists()` - Check if an object exists
|
||||
|
||||
### Timing/Schedules
|
||||
`sched = bl.schedule(timeMs, function, args...)` - Schedule a Lua function to be called later, similar to schedule in Torque
|
||||
@@ -101,10 +103,11 @@ When reading from outside ZIPs, binary files are fully supported.
|
||||
`bl.type('className::funcName', 'type')` - Register the return type of a Torque object method.
|
||||
`bl.class('className')` - Register an existing Torque class to be used from Lua. Already done for all built-in classes.
|
||||
`bl.class('className', 'parentClassName')` - Same as above, with inheritance
|
||||
`bl.boolean(thing)` - Manually convert a Torque boolean (0 or 1) into a Lua boolean.
|
||||
`bl.object(thing)` - Manually convert a Torque object reference (object ID or name) into a Lua object.
|
||||
`bl.boolean(arg)` - Manually convert a Torque boolean (0 or 1) into a Lua boolean.
|
||||
`bl.object(arg)` - Manually convert a Torque object reference (object ID or name) into a Lua object.
|
||||
`bl.string(arg)` - Manually convert any automatically-converted Torque value back into a string. This is not as reliable as using `bl.type` to specify the type as a string beforehand.
|
||||
|
||||
### Vectors
|
||||
### Vector
|
||||
`vec = vector{x,y,z}` - Create a vector. Can have any number of elements
|
||||
`vec1 + vec2` - Add
|
||||
`vec1 - vec2` - Subtract
|
||||
@@ -129,6 +132,9 @@ When reading from outside ZIPs, binary files are fully supported.
|
||||
`vec1:distance(vec2)` - Distance between two points
|
||||
`vec2 = vec:copy()` - Clone a vector so its elements can be modified without affecting the original. Usually not needed - the builtin vector functions never modify vectors in-place.
|
||||
|
||||
### Matrix
|
||||
WIP
|
||||
|
||||
### Extended Standard Lua Library
|
||||
`string[index]`
|
||||
`string[{start,stop}]`
|
||||
@@ -163,12 +169,7 @@ When reading from outside ZIPs, binary files are fully supported.
|
||||
## Type Conversion
|
||||
When a TorqueScript function is called from Lua or vice-versa, the arguments and return value must be converted between the two languages' type systems.
|
||||
TorqueScript stores no type information; all values in TorqueScript are strings. So it's necessary to make some inferences when converting values between the two languages.
|
||||
### From TorqueScript to Lua
|
||||
- Any numeric value becomes a Lua `number`, except as specified with `bl.type`, which may convert a value into a `boolean` or a Torque object container.
|
||||
- The empty string "" becomes `nil`
|
||||
- A string containing three numbers separated by spaces becomes a `vector`
|
||||
- A string containing six numbers separated by spaces becomes a table of two vectors
|
||||
- Any other string is passed directly as a `string`
|
||||
|
||||
### From Lua to TorqueScript
|
||||
- `nil` becomes the empty string ""
|
||||
- `true` and `false` become "1" and "0" respectively
|
||||
@@ -178,6 +179,17 @@ TorqueScript stores no type information; all values in TorqueScript are strings.
|
||||
- Any `string` is passed directly as a string
|
||||
- Tables cannot be passed and will throw an error
|
||||
|
||||
### From TorqueScript to Lua
|
||||
- Any numeric value becomes a Lua `number`, except as specified with `bl.type`, which may convert a value into a `boolean` or a Torque object container.
|
||||
- The empty string "" becomes `nil`
|
||||
- A string containing two or three numbers separated by single spaces becomes a `vector`
|
||||
- A string containing six numbers separated by single spaces becomes a table of two vectors, usually defining the corners a bounding box
|
||||
- (WIP) A string containing seven numbers separated by single spaces is treated as an axis-angle (a "transform" in TorqueScript parlance), and is converted into a `matrix` representing the translation and rotation.
|
||||
- Any other string is passed directly as a `string`
|
||||
|
||||
For scenarios where the automatic TorqueScript->Lua conversion rules are insufficient or incorrect, use `bl.type`.
|
||||
To convert objects by hand, use `bl.object`, `bl.boolean`, or `bl.string`.
|
||||
|
||||
## I/O and Safety
|
||||
All Lua code is sandboxed, and file access is confined to the default directories in the same way TorqueScript is.
|
||||
BlockLua also has access to any C libraries installed in the `modules/lualib` folder, so be careful throwing things in there.
|
||||
|
||||
Reference in New Issue
Block a user