-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathgrpc-mission.lua
More file actions
71 lines (61 loc) · 1.96 KB
/
Copy pathgrpc-mission.lua
File metadata and controls
71 lines (61 loc) · 1.96 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
if not GRPC then
GRPC = {
-- scaffold nested tables to allow direct assignment in config file
tts = { provider = { gcloud = {}, aws = {}, azure = {}, win = {}, parler = {} } },
srs = {},
auth = { tokens = {} }
}
end
-- load settings from `Saved Games/DCS/Config/dcs-grpc.lua`
do
env.info("[GRPC] Checking optional config at `Config/dcs-grpc.lua` ...")
local file, err = io.open(lfs.writedir() .. [[Config\dcs-grpc.lua]], "r")
if file then
local f = assert(loadstring(file:read("*all")))
setfenv(f, GRPC)
f()
env.info("[GRPC] `Config/dcs-grpc.lua` successfully read")
else
env.info("[GRPC] `Config/dcs-grpc.lua` not found (" .. tostring(err) .. ")")
end
end
-- Set default settings.
if not GRPC.luaPath then
GRPC.luaPath = lfs.writedir() .. [[Scripts\DCS-gRPC\]]
end
if not GRPC.dllPath then
GRPC.dllPath = lfs.writedir() .. [[Mods\tech\DCS-gRPC\]]
end
if GRPC.throughputLimit == nil or GRPC.throughputLimit == 0 or type(GRPC.throughputLimit) ~= "number" then
GRPC.throughputLimit = 600
end
-- load version
dofile(GRPC.luaPath .. [[version.lua]])
-- Let DCS know where to find the DLLs
if not string.find(package.cpath, GRPC.dllPath) then
package.cpath = package.cpath .. [[;]] .. GRPC.dllPath .. [[?.dll;]]
end
-- Load DLL before `require` gets sanitized.
local ok, grpc = pcall(require, "dcs_grpc_hot_reload")
if ok then
env.info("[GRPC] loaded hot reload version")
else
grpc = require("dcs_grpc")
end
-- Keep a reference to `lfs` before it gets sanitized
local lfs = _G.lfs
local loaded = false
function GRPC.load()
if loaded then
env.info("[GRPC] already loaded")
return
end
local env = setmetatable({ grpc = grpc, lfs = lfs }, { __index = _G })
local f = setfenv(assert(loadfile(GRPC.luaPath .. [[grpc.lua]])), env)
f()
loaded = true
end
if GRPC.autostart == true then
env.info("[GRPC] auto starting")
GRPC.load()
end