Skip to content

Commit 497076d

Browse files
committed
chore: refactor shit
1 parent 675b8f1 commit 497076d

6 files changed

Lines changed: 134 additions & 45 deletions

File tree

build_log.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
install
2+
+- install lullaby
3+
+- compile lib lullaby ReleaseSafe x86_64-windows 1 errors
4+
src\lullaby.zig:54:48: error: expected type 'i32', found 'win32.ui.input.keyboard_and_mouse.VIRTUAL_KEY'
5+
while (windows.GetAsyncKeyState(windows.VK_END) == 0) {
6+
~~~~~~~^~~~~~~
7+
C:\Users\Nulm\AppData\Local\zig\p\zigwin32-25.0.28-preview-AAAAANd_5APbcon3QqoYfLKnJ13fiBGJSGq9YrVZsfI-\win32\ui\input\keyboard_and_mouse.zig:362:25: note: enum declared here
8+
pub const VIRTUAL_KEY = enum(u16) {
9+
^~~~
10+
C:\Users\Nulm\AppData\Local\zig\p\zigwin32-25.0.28-preview-AAAAANd_5APbcon3QqoYfLKnJ13fiBGJSGq9YrVZsfI-\win32\ui\input\keyboard_and_mouse.zig:1193:11: note: parameter type declared here
11+
vKey: i32,
12+
^~~
13+
referenced by:
14+
threadMain: src\lullaby.zig:68:17
15+
callFn__anon_3893: C:\Users\Nulm\AppData\Roaming\Antigravity\User\globalStorage\ziglang.vscode-zig\zig\x86_64-windows-0.15.2\lib\std\Thread.zig:509:13
16+
8 reference(s) hidden; use '-freference-trace=10' to see all references
17+
error: the following command failed with 1 compilation errors:
18+
"C:\\Users\\Nulm\\AppData\\Roaming\\Antigravity\\User\\globalStorage\\ziglang.vscode-zig\\zig\\x86_64-windows-0.15.2\\zig.exe" build-lib "C:\\Users\\Nulm\\AppData\\Local\\zig\\p\\N-V-__8AAMzvGBK7HPhognpMDIVEkov8BMEXwbCCzyow9hax\\lib\\JVM.lib" -OReleaseSafe -target x86_64-windows -mcpu baseline --dep JNI --dep http --dep win32 --dep websocket --dep luau "-Mroot=C:\\Users\\Nulm\\source\\repos\\lullaby\\src\\main.zig" -OReleaseSafe --dep cjni "-MJNI=C:\\Users\\Nulm\\AppData\\Local\\zig\\p\\jni-0.0.1-qf3mHEoJBADgTJirCPl6I65kKz6-PBwsV7PgN_EX6AQy\\src\\main\\zig\\lib.zig" -OReleaseSafe --dep metrics --dep websocket=websocket0 --dep build "-Mhttp=C:\\Users\\Nulm\\AppData\\Local\\zig\\p\\httpz-0.0.0-PNVzrIowBwAFr_kqBN1W4KBMC2Ofutasj2ZfNAIcfTzF\\src\\httpz.zig" "-Mwin32=C:\\Users\\Nulm\\AppData\\Local\\zig\\p\\zigwin32-25.0.28-preview-AAAAANd_5APbcon3QqoYfLKnJ13fiBGJSGq9YrVZsfI-\\win32.zig" -OReleaseSafe --dep build=build0 "-Mwebsocket=C:\\Users\\Nulm\\AppData\\Local\\zig\\p\\websocket-0.1.0-ZPISdRNzAwAGszh62EpRtoQxu8wb1MSMVI6Ow0o2dmyJ\\src\\websocket.zig" ".zig-cache\\o\\2e456454d07bc68392fe12660a237976\\luau.lib" -I "C:\\Users\\Nulm\\AppData\\Local\\zig\\p\\N-V-__8AAFB1kwDHb7dLmDsOv91rOkqorfDB_2nJtqnp4F-b\\Common\\include" -I "C:\\Users\\Nulm\\AppData\\Local\\zig\\p\\N-V-__8AAFB1kwDHb7dLmDsOv91rOkqorfDB_2nJtqnp4F-b\\Compiler\\include" -I "C:\\Users\\Nulm\\AppData\\Local\\zig\\p\\N-V-__8AAFB1kwDHb7dLmDsOv91rOkqorfDB_2nJtqnp4F-b\\Ast\\include" -I "C:\\Users\\Nulm\\AppData\\Local\\zig\\p\\N-V-__8AAFB1kwDHb7dLmDsOv91rOkqorfDB_2nJtqnp4F-b\\VM\\include" -I ".zig-cache\\o\\fc14f47b06b269e74e7a4b7935934a00" -DLUA_VECTOR_SIZE=3 --dep config --dep c "-Mluau=C:\\Users\\Nulm\\AppData\\Local\\zig\\p\\zlua-0.1.0-hGRpCww-BQCx3cX6zbKWfTgOx6B7Peo4P17RK2hm7-xV\\src\\lib.zig" -OReleaseSafe "-Mcjni=.zig-cache\\o\\158ded9055d71abdee54028dedcde096\\jni.zig" -OReleaseSafe "-Mmetrics=C:\\Users\\Nulm\\AppData\\Local\\zig\\p\\metrics-0.0.0-W7G4eP2_AQAdJGKMonHeZFaY4oU4ZXPFFTqFCFXItX3O\\src\\metrics.zig" -OReleaseSafe --dep build=build1 "-Mwebsocket0=C:\\Users\\Nulm\\AppData\\Local\\zig\\p\\websocket-0.1.0-ZPISdZJxAwAt6Ys_JpoHQQV3NpWCof_N9Jg-Ul2g7OoV\\src\\websocket.zig" "-Mbuild=.zig-cache\\c\\c8d85127ed6414d988f389d6a7956048\\options.zig" "-Mbuild0=.zig-cache\\c\\9df3ebb56e512146581134c82a20886e\\options.zig" "-Mconfig=.zig-cache\\c\\61dfe967e136e88b9ffc86d5425e5363\\options.zig" -OReleaseSafe -target x86_64-windows -mcpu baseline "-Mc=.zig-cache\\o\\4617accce7206078acbcfcf57ae8c8f0\\luau_all.zig" "-Mbuild1=.zig-cache\\c\\9df3ebb56e512146581134c82a20886e\\options.zig" -lc++ -lc -femit-implib --cache-dir .zig-cache --global-cache-dir "C:\\Users\\Nulm\\AppData\\Local\\zig" --name lullaby -dynamic --zig-lib-dir "C:\\Users\\Nulm\\AppData\\Roaming\\Antigravity\\User\\globalStorage\\ziglang.vscode-zig\\zig\\x86_64-windows-0.15.2\\lib\\" --listen=-
19+
20+
Build Summary: 9/12 steps succeeded; 1 failed
21+
install transitive failure
22+
+- install lullaby transitive failure
23+
+- compile lib lullaby ReleaseSafe x86_64-windows 1 errors
24+
25+
error: the following build command failed with exit code 1:
26+
.zig-cache\o\a0312268fab226d6f671bf924fe24fc3\build.exe C:\Users\Nulm\AppData\Roaming\Antigravity\User\globalStorage\ziglang.vscode-zig\zig\x86_64-windows-0.15.2\zig.exe C:\Users\Nulm\AppData\Roaming\Antigravity\User\globalStorage\ziglang.vscode-zig\zig\x86_64-windows-0.15.2\lib C:\Users\Nulm\source\repos\lullaby .zig-cache C:\Users\Nulm\AppData\Local\zig --seed 0x2e76ff15 -Zd743f1c6437d530a -Doptimize=ReleaseSafe

build_log_2.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
install
2+
+- install lullaby
3+
+- compile lib lullaby ReleaseSafe x86_64-windows 1 errors
4+
src\lullaby.zig:55:21: error: root source file struct 'time' has no member named 'sleep'
5+
std.time.sleep(50 * std.time.ns_per_ms);
6+
~~~~~~~~^~~~~~
7+
C:\Users\Nulm\AppData\Roaming\Antigravity\User\globalStorage\ziglang.vscode-zig\zig\x86_64-windows-0.15.2\lib\std\time.zig:1:1: note: struct declared here
8+
const std = @import("std.zig");
9+
^~~~~
10+
referenced by:
11+
threadMain: src\lullaby.zig:68:17
12+
callFn__anon_3893: C:\Users\Nulm\AppData\Roaming\Antigravity\User\globalStorage\ziglang.vscode-zig\zig\x86_64-windows-0.15.2\lib\std\Thread.zig:509:13
13+
8 reference(s) hidden; use '-freference-trace=10' to see all references
14+
error: the following command failed with 1 compilation errors:
15+
"C:\\Users\\Nulm\\AppData\\Roaming\\Antigravity\\User\\globalStorage\\ziglang.vscode-zig\\zig\\x86_64-windows-0.15.2\\zig.exe" build-lib "C:\\Users\\Nulm\\AppData\\Local\\zig\\p\\N-V-__8AAMzvGBK7HPhognpMDIVEkov8BMEXwbCCzyow9hax\\lib\\JVM.lib" -OReleaseSafe -target x86_64-windows -mcpu baseline --dep JNI --dep http --dep win32 --dep websocket --dep luau "-Mroot=C:\\Users\\Nulm\\source\\repos\\lullaby\\src\\main.zig" -OReleaseSafe --dep cjni "-MJNI=C:\\Users\\Nulm\\AppData\\Local\\zig\\p\\jni-0.0.1-qf3mHEoJBADgTJirCPl6I65kKz6-PBwsV7PgN_EX6AQy\\src\\main\\zig\\lib.zig" -OReleaseSafe --dep metrics --dep websocket=websocket0 --dep build "-Mhttp=C:\\Users\\Nulm\\AppData\\Local\\zig\\p\\httpz-0.0.0-PNVzrIowBwAFr_kqBN1W4KBMC2Ofutasj2ZfNAIcfTzF\\src\\httpz.zig" "-Mwin32=C:\\Users\\Nulm\\AppData\\Local\\zig\\p\\zigwin32-25.0.28-preview-AAAAANd_5APbcon3QqoYfLKnJ13fiBGJSGq9YrVZsfI-\\win32.zig" -OReleaseSafe --dep build=build0 "-Mwebsocket=C:\\Users\\Nulm\\AppData\\Local\\zig\\p\\websocket-0.1.0-ZPISdRNzAwAGszh62EpRtoQxu8wb1MSMVI6Ow0o2dmyJ\\src\\websocket.zig" ".zig-cache\\o\\2e456454d07bc68392fe12660a237976\\luau.lib" -I "C:\\Users\\Nulm\\AppData\\Local\\zig\\p\\N-V-__8AAFB1kwDHb7dLmDsOv91rOkqorfDB_2nJtqnp4F-b\\Common\\include" -I "C:\\Users\\Nulm\\AppData\\Local\\zig\\p\\N-V-__8AAFB1kwDHb7dLmDsOv91rOkqorfDB_2nJtqnp4F-b\\Compiler\\include" -I "C:\\Users\\Nulm\\AppData\\Local\\zig\\p\\N-V-__8AAFB1kwDHb7dLmDsOv91rOkqorfDB_2nJtqnp4F-b\\Ast\\include" -I "C:\\Users\\Nulm\\AppData\\Local\\zig\\p\\N-V-__8AAFB1kwDHb7dLmDsOv91rOkqorfDB_2nJtqnp4F-b\\VM\\include" -I ".zig-cache\\o\\fc14f47b06b269e74e7a4b7935934a00" -DLUA_VECTOR_SIZE=3 --dep config --dep c "-Mluau=C:\\Users\\Nulm\\AppData\\Local\\zig\\p\\zlua-0.1.0-hGRpCww-BQCx3cX6zbKWfTgOx6B7Peo4P17RK2hm7-xV\\src\\lib.zig" -OReleaseSafe "-Mcjni=.zig-cache\\o\\158ded9055d71abdee54028dedcde096\\jni.zig" -OReleaseSafe "-Mmetrics=C:\\Users\\Nulm\\AppData\\Local\\zig\\p\\metrics-0.0.0-W7G4eP2_AQAdJGKMonHeZFaY4oU4ZXPFFTqFCFXItX3O\\src\\metrics.zig" -OReleaseSafe --dep build=build1 "-Mwebsocket0=C:\\Users\\Nulm\\AppData\\Local\\zig\\p\\websocket-0.1.0-ZPISdZJxAwAt6Ys_JpoHQQV3NpWCof_N9Jg-Ul2g7OoV\\src\\websocket.zig" "-Mbuild=.zig-cache\\c\\c8d85127ed6414d988f389d6a7956048\\options.zig" "-Mbuild0=.zig-cache\\c\\9df3ebb56e512146581134c82a20886e\\options.zig" "-Mconfig=.zig-cache\\c\\61dfe967e136e88b9ffc86d5425e5363\\options.zig" -OReleaseSafe -target x86_64-windows -mcpu baseline "-Mc=.zig-cache\\o\\4617accce7206078acbcfcf57ae8c8f0\\luau_all.zig" "-Mbuild1=.zig-cache\\c\\9df3ebb56e512146581134c82a20886e\\options.zig" -lc++ -lc -femit-implib --cache-dir .zig-cache --global-cache-dir "C:\\Users\\Nulm\\AppData\\Local\\zig" --name lullaby -dynamic --zig-lib-dir "C:\\Users\\Nulm\\AppData\\Roaming\\Antigravity\\User\\globalStorage\\ziglang.vscode-zig\\zig\\x86_64-windows-0.15.2\\lib\\" --listen=-
16+
17+
Build Summary: 9/12 steps succeeded; 1 failed
18+
install transitive failure
19+
+- install lullaby transitive failure
20+
+- compile lib lullaby ReleaseSafe x86_64-windows 1 errors
21+
22+
error: the following build command failed with exit code 1:
23+
.zig-cache\o\a0312268fab226d6f671bf924fe24fc3\build.exe C:\Users\Nulm\AppData\Roaming\Antigravity\User\globalStorage\ziglang.vscode-zig\zig\x86_64-windows-0.15.2\zig.exe C:\Users\Nulm\AppData\Roaming\Antigravity\User\globalStorage\ziglang.vscode-zig\zig\x86_64-windows-0.15.2\lib C:\Users\Nulm\source\repos\lullaby .zig-cache C:\Users\Nulm\AppData\Local\zig --seed 0x5acb1aac -Zf7a95900351e5c22 -Doptimize=ReleaseSafe

build_log_3.txt

Whitespace-only changes.

src/lullaby.zig

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
const std = @import("std");
2+
const jni = @import("JNI");
3+
const win32 = @import("win32");
4+
5+
const cjni = jni.cjni;
6+
const windows = win32.everything;
7+
8+
pub const Lullaby = struct {
9+
handle: std.os.windows.HMODULE,
10+
jvm: jni.JavaVM,
11+
env: jni.JNIEnv,
12+
13+
const log = std.log.scoped(.lullaby);
14+
15+
pub fn init(handle: std.os.windows.HMODULE) !Lullaby {
16+
var jvm_buf: [1][*c]cjni.JavaVM = undefined;
17+
var count: cjni.jint = 0;
18+
19+
const res = cjni.JNI_GetCreatedJavaVMs(&jvm_buf, 1, &count);
20+
if (res != cjni.JNI_OK) {
21+
log.err("JNI_GetCreatedJavaVMs failed with code: {}", .{res});
22+
return error.JniInitFailed;
23+
}
24+
if (count == 0) {
25+
log.err("No JVM found in the target process.", .{});
26+
return error.NoJvmFound;
27+
}
28+
29+
var jvm = jni.JavaVM.warp(jvm_buf[0]);
30+
var env: jni.JNIEnv = undefined;
31+
32+
try jvm.attachCurrentThreadAsDaemon(&env, null);
33+
log.info("Attached to JVM successfully.", .{});
34+
35+
return Lullaby{
36+
.handle = handle,
37+
.jvm = jvm,
38+
.env = env,
39+
};
40+
}
41+
42+
pub fn deinit(self: *Lullaby) void {
43+
self.jvm.detachCurrentThread() catch |err| {
44+
log.err("Failed to detach thread from JVM: {}", .{err});
45+
};
46+
log.info("Detached from JVM.", .{});
47+
}
48+
49+
pub fn run(self: *Lullaby) !void {
50+
defer self.deinit();
51+
52+
log.info("Lullaby running.", .{});
53+
54+
while (windows.GetAsyncKeyState(@as(i32, @intFromEnum(windows.VK_END))) == 0) {
55+
windows.Sleep(50);
56+
}
57+
}
58+
};
59+
60+
pub fn threadMain(handle: std.os.windows.HMODULE) void {
61+
const log = std.log.scoped(.lullaby_thread);
62+
63+
var instance = Lullaby.init(handle) catch |err| {
64+
log.err("Failed to initialize Lullaby: {}", .{err});
65+
windows.FreeLibraryAndExitThread(@ptrCast(handle), 0);
66+
return;
67+
};
68+
instance.run() catch |err| {
69+
log.err("Runtime error: {}", .{err});
70+
};
71+
72+
log.info("Unloading Lullaby DLL...", .{});
73+
windows.FreeLibraryAndExitThread(@ptrCast(handle), 0);
74+
}

src/main.zig

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
const std = @import("std");
2-
const main = @import("thread.zig");
3-
const windows = @import("win32").everything;
2+
const lullaby = @import("lullaby.zig");
3+
const win32 = @import("win32");
4+
const windows = win32.everything;
45

56
pub fn DllMain(
6-
h_module: std.os.windows.HINSTANCE,
7+
handle: std.os.windows.HINSTANCE,
78
fdw_reason: u32,
89
_: *anyopaque,
9-
) callconv(.winapi) std.os.windows.BOOL {
10+
) callconv(.winapi) windows.BOOL {
1011
switch (fdw_reason) {
1112
windows.DLL_PROCESS_ATTACH => {
12-
_ = windows.DisableThreadLibraryCalls(@ptrCast(@alignCast(h_module)));
13-
return main.startThread(@ptrCast(h_module)) catch {
13+
_ = windows.DisableThreadLibraryCalls(@ptrCast(@alignCast(handle)));
14+
15+
const thread = std.Thread.spawn(.{}, lullaby.threadMain, .{@as(std.os.windows.HMODULE, @ptrCast(handle))}) catch |err| {
16+
std.log.err("Failed to spawn Lullaby thread: {}", .{err});
1417
return 0;
1518
};
19+
20+
thread.detach();
1621
},
1722
windows.DLL_PROCESS_DETACH => {},
1823
else => {},

src/thread.zig

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)