From ea70f2f00797eab8eeccc58cb6034697439e15d2 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 15 Jun 2026 22:23:50 +0000 Subject: [PATCH] Auto-load the native library on Linux via the Kit (platform-gated) b2kSetup now calls b2LoadNativeLibHere() when (and only when) the platform is Linux, so Kit/demo users get the no-sudo engine-folder load automatically while Windows/macOS never touch the POSIX path. The breakage that forced the helper to be a manual call in #47 was Windows-only -- realpath is absent there, but present and harmless on macOS -- so a single platform gate is enough. Drop box2dxt.so beside the engine (or bundle it in a standalone) and the demos run on Linux with no /usr/lib, no sudo, no LD_LIBRARY_PATH. - src/box2dxt-kit.livecodescript: gated preload at the top of b2kSetup. - examples/*: re-synced embedded Kit. - examples/box2dxt-selftest: bump kStHarnessV 18->19 + add stTestLoaderHelper (Linux-gated; on Linux it also proves the realpath/dlopen bindings resolve). https://claude.ai/code/session_01EVV5fGeXqtWs8WDrmgWNku --- ...box2dxt-contraption-builder.livecodescript | 6 +++++ examples/box2dxt-demo.livecodescript | 6 +++++ examples/box2dxt-platformer.livecodescript | 6 +++++ examples/box2dxt-selftest.livecodescript | 24 ++++++++++++++++++- examples/box2dxt-slingshot.livecodescript | 6 +++++ examples/box2dxt-spike-gamekit.livecodescript | 6 +++++ src/box2dxt-kit.livecodescript | 6 +++++ 7 files changed, 59 insertions(+), 1 deletion(-) diff --git a/examples/box2dxt-contraption-builder.livecodescript b/examples/box2dxt-contraption-builder.livecodescript index 2c07cdc..aa50de1 100644 --- a/examples/box2dxt-contraption-builder.livecodescript +++ b/examples/box2dxt-contraption-builder.livecodescript @@ -319,6 +319,12 @@ constant kPI = 3.14159265358979 -- World / lifecycle -- ===================================================================== command b2kSetup pGravityX, pGravityY + -- On Linux the engine will not find box2dxt.so sitting beside it on its own, + -- so preload it from the engine's OWN folder before the first physics call. + -- LINUX-ONLY on purpose: b2LoadNativeLibHere uses POSIX calls that do not + -- exist on Windows, and Windows/macOS already load the library from beside + -- the stack/app -- so the platform check keeps it from ever firing there. + if the platform is "Linux" then get b2LoadNativeLibHere() b2kTeardown if pGravityX is empty then put 0 into pGravityX if pGravityY is empty then put -10 into pGravityY diff --git a/examples/box2dxt-demo.livecodescript b/examples/box2dxt-demo.livecodescript index 9f7019d..8c1d28b 100644 --- a/examples/box2dxt-demo.livecodescript +++ b/examples/box2dxt-demo.livecodescript @@ -309,6 +309,12 @@ constant kPI = 3.14159265358979 -- World / lifecycle -- ===================================================================== command b2kSetup pGravityX, pGravityY + -- On Linux the engine will not find box2dxt.so sitting beside it on its own, + -- so preload it from the engine's OWN folder before the first physics call. + -- LINUX-ONLY on purpose: b2LoadNativeLibHere uses POSIX calls that do not + -- exist on Windows, and Windows/macOS already load the library from beside + -- the stack/app -- so the platform check keeps it from ever firing there. + if the platform is "Linux" then get b2LoadNativeLibHere() b2kTeardown if pGravityX is empty then put 0 into pGravityX if pGravityY is empty then put -10 into pGravityY diff --git a/examples/box2dxt-platformer.livecodescript b/examples/box2dxt-platformer.livecodescript index 2928a7e..25bd37a 100644 --- a/examples/box2dxt-platformer.livecodescript +++ b/examples/box2dxt-platformer.livecodescript @@ -4388,6 +4388,12 @@ constant kPI = 3.14159265358979 -- World / lifecycle -- ===================================================================== command b2kSetup pGravityX, pGravityY + -- On Linux the engine will not find box2dxt.so sitting beside it on its own, + -- so preload it from the engine's OWN folder before the first physics call. + -- LINUX-ONLY on purpose: b2LoadNativeLibHere uses POSIX calls that do not + -- exist on Windows, and Windows/macOS already load the library from beside + -- the stack/app -- so the platform check keeps it from ever firing there. + if the platform is "Linux" then get b2LoadNativeLibHere() b2kTeardown if pGravityX is empty then put 0 into pGravityX if pGravityY is empty then put -10 into pGravityY diff --git a/examples/box2dxt-selftest.livecodescript b/examples/box2dxt-selftest.livecodescript index ec14e24..91213b2 100644 --- a/examples/box2dxt-selftest.livecodescript +++ b/examples/box2dxt-selftest.livecodescript @@ -47,7 +47,7 @@ local gRep, gPass, gFail, gFellCount, gRunning local gMsgEnters, gMsgContacts -- message-path counters (vs polling) constant kStUIVersion = "1" -constant kStHarnessV = "18" -- bump on EVERY harness change: the report +constant kStHarnessV = "19" -- bump on EVERY harness change: the report -- header prints it, so a stale paste is -- visible at a glance @@ -124,6 +124,7 @@ command stRunAll stRun "stTestCamera" stRun "stTestCamScrolledWrite" stRun "stTestEngineContracts" + stRun "stTestLoaderHelper" stRun "stTestMaterialsJoints" stRun "stTestFiltering" stRun "stTestQueries" @@ -275,6 +276,21 @@ end stVX -- ===================================================================== -- The tests -- ===================================================================== +-- The Kit auto-preloads the native library on Linux via b2LoadNativeLibHere +-- (gated in b2kSetup so it only fires when the platform is Linux). The helper +-- is POSIX-only, so it must NEVER run off Linux -- exercise it only there, and +-- elsewhere just record that the gate skips it. On Linux this also proves the +-- realpath/dlopen bindings resolve (a bad binding would throw and FAIL here). +command stTestLoaderHelper + if the platform is "Linux" then + put b2LoadNativeLibHere() into tR + stAssert "b2LoadNativeLibHere returns a 0/1 flag without error (got " & tR & ")", \ + (tR is 0 or tR is 1) + else + stAssert "loader auto-preload is Linux-gated (skipped on " & the platform & ")", true + end if +end stTestLoaderHelper + command stTestWorld local tRef, tY1, tVy stNewWorld "world & fixed-step determinism" @@ -1733,6 +1749,12 @@ constant kPI = 3.14159265358979 -- World / lifecycle -- ===================================================================== command b2kSetup pGravityX, pGravityY + -- On Linux the engine will not find box2dxt.so sitting beside it on its own, + -- so preload it from the engine's OWN folder before the first physics call. + -- LINUX-ONLY on purpose: b2LoadNativeLibHere uses POSIX calls that do not + -- exist on Windows, and Windows/macOS already load the library from beside + -- the stack/app -- so the platform check keeps it from ever firing there. + if the platform is "Linux" then get b2LoadNativeLibHere() b2kTeardown if pGravityX is empty then put 0 into pGravityX if pGravityY is empty then put -10 into pGravityY diff --git a/examples/box2dxt-slingshot.livecodescript b/examples/box2dxt-slingshot.livecodescript index 729c288..8e0d5b2 100644 --- a/examples/box2dxt-slingshot.livecodescript +++ b/examples/box2dxt-slingshot.livecodescript @@ -1066,6 +1066,12 @@ constant kPI = 3.14159265358979 -- World / lifecycle -- ===================================================================== command b2kSetup pGravityX, pGravityY + -- On Linux the engine will not find box2dxt.so sitting beside it on its own, + -- so preload it from the engine's OWN folder before the first physics call. + -- LINUX-ONLY on purpose: b2LoadNativeLibHere uses POSIX calls that do not + -- exist on Windows, and Windows/macOS already load the library from beside + -- the stack/app -- so the platform check keeps it from ever firing there. + if the platform is "Linux" then get b2LoadNativeLibHere() b2kTeardown if pGravityX is empty then put 0 into pGravityX if pGravityY is empty then put -10 into pGravityY diff --git a/examples/box2dxt-spike-gamekit.livecodescript b/examples/box2dxt-spike-gamekit.livecodescript index 0726de5..b1321de 100644 --- a/examples/box2dxt-spike-gamekit.livecodescript +++ b/examples/box2dxt-spike-gamekit.livecodescript @@ -1646,6 +1646,12 @@ constant kPI = 3.14159265358979 -- World / lifecycle -- ===================================================================== command b2kSetup pGravityX, pGravityY + -- On Linux the engine will not find box2dxt.so sitting beside it on its own, + -- so preload it from the engine's OWN folder before the first physics call. + -- LINUX-ONLY on purpose: b2LoadNativeLibHere uses POSIX calls that do not + -- exist on Windows, and Windows/macOS already load the library from beside + -- the stack/app -- so the platform check keeps it from ever firing there. + if the platform is "Linux" then get b2LoadNativeLibHere() b2kTeardown if pGravityX is empty then put 0 into pGravityX if pGravityY is empty then put -10 into pGravityY diff --git a/src/box2dxt-kit.livecodescript b/src/box2dxt-kit.livecodescript index 65cf0b7..2b24fe2 100644 --- a/src/box2dxt-kit.livecodescript +++ b/src/box2dxt-kit.livecodescript @@ -283,6 +283,12 @@ constant kPI = 3.14159265358979 -- World / lifecycle -- ===================================================================== command b2kSetup pGravityX, pGravityY + -- On Linux the engine will not find box2dxt.so sitting beside it on its own, + -- so preload it from the engine's OWN folder before the first physics call. + -- LINUX-ONLY on purpose: b2LoadNativeLibHere uses POSIX calls that do not + -- exist on Windows, and Windows/macOS already load the library from beside + -- the stack/app -- so the platform check keeps it from ever firing there. + if the platform is "Linux" then get b2LoadNativeLibHere() b2kTeardown if pGravityX is empty then put 0 into pGravityX if pGravityY is empty then put -10 into pGravityY