Lua API
基本信息
| 属性 |
值 |
| Lua 函数总数 |
29 |
| 源码位置 |
surface/widgets/core/luafunction/(29 个文件,每个一个函数) |
| 基类 |
LuaFunction implements Value(lua/LuaFunction.java:14) |
| 参考类 |
LuaReference(lua/LuaReference.java) |
| 运行环境 |
OpenComputers Lua(li.cil.oc.api.machine.*) |
OCGlasses 把 29 个函数注入 OpenComputers 的 Lua 虚拟机,在眼镜终端的 openos 中直接可用,用于操纵 Widget System 的图元。
全部 29 个函数
函数名取自各类的 getName() 返回值(LuaFunction.java:21 声明为 public abstract String getName())。
位置与朝向(8)
| Lua 名 |
类 |
getPosition |
GetPosition |
setPosition |
SetPosition |
get3DPos |
GetPosition3D |
set3DPos |
SetPosition3D |
getRotation |
GetRotation |
setRotation |
SetRotation |
getLookingAt |
GetLookingAt |
setLookingAt |
SetLookingAt |
尺寸与缩放(4)
| Lua 名 |
类 |
getSize |
GetSize |
setSize |
SetSize |
getScale |
GetScale |
setScale |
SetScale |
外观(4)
| Lua 名 |
类 |
getAlpha |
GetAlpha |
setAlpha |
SetAlpha |
getColor |
GetColor |
setColor |
SetColor |
可见性(4)
| Lua 名 |
类 |
isVisible |
IsVisible |
setVisible |
SetVisible |
isVisibleThroughObjects |
IsVisibleThroughObjects |
setVisibleThroughObjects |
SetVisibleThroughObjects |
内容(4)
| Lua 名 |
类 |
getText |
GetText |
setText |
SetText |
getItem |
GetItem |
setItem |
SetItem |
其它(5)
| Lua 名 |
类 |
getID |
GetID |
getVertexCount |
GetVertexCount |
setVertex |
SetVertex |
getViewDistance |
GetViewDistance |
setViewDistance |
SetViewDistance |
对照:2D / 3D 命名不对称
getPosition / setPosition 与 get3DPos / set3DPos 命名不对称——3D 版本用 3DPos 而非 Position3D。这是源码实际命名,脚本中必须照此写。
Value 接口实现
LuaFunction implements Value(li.cil.oc.api.machine.Value),并实现了 NBT 持久化:
public void load(NBTTagCompound nbt) {
ref = new LuaReference().readFromNBT(nbt.getCompoundTag("ref"));
}
public void save(NBTTagCompound nbt) {
NBTTagCompound refTag = new NBTTagCompound();
ref.writeToNBT(refTag);
nbt.setTag("ref", refTag);
}
即图元的引用(LuaReference)可随存档序列化,脚本重建后可重新绑定到同一图元。
LuaReference 持有 id 与 Location(世界坐标),是 OC 侧定位图元的句柄。
相关条目