diff --git a/output.bin b/output.bin index 066fa29..f0d2372 100644 Binary files a/output.bin and b/output.bin differ diff --git a/src/lua.cpp b/src/lua.cpp index c923543..d501f13 100644 --- a/src/lua.cpp +++ b/src/lua.cpp @@ -34,29 +34,43 @@ end // Lua helpers static int gameobjectSetPosition(psyqo::Lua L) { + auto go = L.toUserdata(1); + L.getField(2, "x"); - go->position.x = L.toFixedPoint(3); + psyqo::FixedPoint<> x(L.toNumber(3), psyqo::FixedPoint<>::RAW); + go->position.x = x; L.pop(); + L.getField(2, "y"); - go->position.y = L.toFixedPoint(3); + psyqo::FixedPoint<> y(L.toNumber(3), psyqo::FixedPoint<>::RAW); + go->position.y = y; L.pop(); L.getField(2, "z"); - go->position.z = L.toFixedPoint(3); + + psyqo::FixedPoint<> z(L.toNumber(3), psyqo::FixedPoint<>::RAW); + go->position.z = z; L.pop(); return 0; + } + + static int gameobjectGetPosition(psyqo::Lua L) { + auto go = L.toUserdata(1); + L.newTable(); - L.push(go->position.x); + L.pushNumber(go->position.x.raw()); L.setField(2, "x"); - L.push(go->position.y); + L.pushNumber(go->position.y.raw()); L.setField(2, "y"); - L.push(go->position.z); + L.pushNumber(go->position.z.raw()); L.setField(2, "z"); + return 1; + } void psxsplash::Lua::Init() { diff --git a/src/lua.h b/src/lua.h index 38a5960..09f652c 100644 --- a/src/lua.h +++ b/src/lua.h @@ -42,13 +42,17 @@ class Lua { typedef irqus::typestring methodName; // Needs the methods table at index 1, and the script environment table at index 3 static void resolveGlobal(psyqo::Lua L) { - L.pushNumber(methodId); - L.getTable(3); + // Push the method name string to access the environment table + L.push(methodName::data(), methodName::size()); + L.getTable(3); + if (L.isFunction(-1)) { - L.push(methodName::data(), methodName::size()); - L.setTable(1); + // Store the function in methods table using numeric ID as key + L.pushNumber(methodId); // Push numeric key for methods table + L.copy(-2); // Push the function (copy from top -2) + L.setTable(1); // methodsTable[methodId] = function } else { - L.pop(); + L.pop(); // Pop the non-function value } } template diff --git a/src/scenemanager.cpp b/src/scenemanager.cpp index 52bce6e..2211853 100644 --- a/src/scenemanager.cpp +++ b/src/scenemanager.cpp @@ -67,5 +67,5 @@ void psxsplash::SceneManager::GameTick() { static_cast>(m_playerPosition.z)); m_currentCamera.SetRotation(playerRotationX, playerRotationY, playerRotationZ); - L.OnCollision(m_gameObjects[0], m_gameObjects[1]); // Example call, replace with actual logic + L.OnCollision(m_gameObjects[1], m_gameObjects[0]); // Example call, replace with actual logic } \ No newline at end of file