-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.lua
More file actions
92 lines (79 loc) · 3.24 KB
/
start.lua
File metadata and controls
92 lines (79 loc) · 3.24 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
-- DaniX start script: boot the kernel in GUI mode and launch the desktop process
-- Usage in CC:Tweaked: run /DaniX/start.lua
-- Try to load a module via require, falling back to absolute /src paths with dofile
local function load_module(modname)
-- try require first
local ok, mod = pcall(require, modname)
if ok and mod then return mod, "require" end
-- try absolute path under /src
local path = "/src/" .. modname:gsub("%.", "/") .. ".lua"
local ok2, mod2 = pcall(dofile, path)
if ok2 and mod2 then
-- Register loaded module so later require() calls will find it
pcall(function() package.loaded[modname] = mod2 end)
return mod2, "dofile_path"
end
-- try init.lua variant
local path2 = "/src/" .. modname:gsub("%.", "/") .. "/init.lua"
local ok3, mod3 = pcall(dofile, path2)
if ok3 and mod3 then
pcall(function() package.loaded[modname] = mod3 end)
return mod3, "dofile_init"
end
return nil, "module not found: " .. modname
end
local kernel, loader_used_or_err = load_module("src.kernel")
local errk = nil
if not kernel then errk = loader_used_or_err end
if not kernel then
-- try api kernel directly
kernel, loader_used_or_err = load_module("src.api.kernel")
if not kernel then errk = loader_used_or_err end
end
local main, loader_used_or_err2 = load_module("src.main")
local errm = nil
if not main then errm = loader_used_or_err2 end
if not kernel or not main then
print("Failed to load kernel or main:", errk, errm, "loader_used:", loader_used_or_err, loader_used_or_err2)
return
end
-- Initialize kernel in GUI mode (no shell)
pcall(function() kernel.init({ no_shell = true }) end)
-- Ensure the scheduler is running so kernel-created processes actually execute.
-- Calling start_scheduler from top-level is allowed (kernel treats non-process callers as system).
if kernel.start_scheduler then
local ok, msg = pcall(kernel.start_scheduler)
if ok then
print("Scheduler start requested: ", tostring(msg))
else
print("Scheduler failed to start: ", tostring(msg))
end
end
-- Create a login process that will show the login prompt and then create the
-- desktop process for the logged-in user. Running the login as a kernel-managed
-- process lets the scheduler run it and deliver events.
-- Run the login directly on the main thread so interactive `read()` works.
local init = require("DaniX.init")
init.run()
-- init.run() will create the desktop via the kernel when login completes.
-- Start the kernel GUI loop (this will start the scheduler and begin handling events)
if main.run_gui then
-- call debug helper to dump process/scheduler state
pcall(function()
local dbg_ok, dbg = pcall(require, "scripts.debug_processes")
if dbg_ok and dbg and type(dbg.dump) == "function" then
dbg.dump()
end
end)
-- Instead of re-entering the kernel GUI loop, drive the scheduler here so the
-- created desktop process actually executes. This keeps the starter simple
-- and avoids recursive starts.
while true do
-- Drive one scheduler tick
if kernel.tick then
pcall(kernel.tick)
end
-- Small sleep so we don't busy-loop
os.sleep(0.05)
end
end