-
Notifications
You must be signed in to change notification settings - Fork 38
/
unity-generate.lua
44 lines (39 loc) · 1.23 KB
/
unity-generate.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
template = [[
public void RegisterCallback($WrappedCallback callback) {
Start(); // make sure the interface is initialized.
if (null == $WrappedList) {
$WrappedList = callback;
raw$WrappedCallback = new OSVR.ClientKit.$RawCallbackType($RawCallback);
iface.registerCallback (raw$WrappedCallback, System.IntPtr.Zero);
} else {
$WrappedList += callback;
}
}
private OSVR.ClientKit.$RawCallbackType raw$WrappedCallback;
private $WrappedCallback $WrappedList;
]]
function generate(data)
s = string.gsub(template, "$(%w+)", function (n)
return data[n]
end)
return s
end
print "/* BEGIN GENERATED CODE - unity-generate.lua */"
print(generate{
WrappedCallback = "PoseMatrixCallback";
WrappedList = "poseMatrixCallbacks";
RawCallback = "PoseMatrixCb";
RawCallbackType = "PoseCallback";
})
for _, v in ipairs{"Pose", "Position", "Orientation", "Button", "Analog"} do
local CapsName = v
local nocapsName = v:sub(1, 1):lower() .. v:sub(2)
local vals = {
WrappedCallback = CapsName .. "Callback";
WrappedList = nocapsName .. "Callbacks";
RawCallback = CapsName .. "Cb";
RawCallbackType = CapsName .. "Callback";
}
print(generate(vals))
end
print "/* END GENERATED CODE - unity-generate.lua */"