Fixed lua function resolution, reverted fixed point handling
This commit is contained in:
BIN
output.bin
BIN
output.bin
Binary file not shown.
26
src/lua.cpp
26
src/lua.cpp
@@ -34,29 +34,43 @@ end
|
|||||||
// Lua helpers
|
// Lua helpers
|
||||||
|
|
||||||
static int gameobjectSetPosition(psyqo::Lua L) {
|
static int gameobjectSetPosition(psyqo::Lua L) {
|
||||||
|
|
||||||
auto go = L.toUserdata<psxsplash::GameObject>(1);
|
auto go = L.toUserdata<psxsplash::GameObject>(1);
|
||||||
|
|
||||||
L.getField(2, "x");
|
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.pop();
|
||||||
|
|
||||||
L.getField(2, "y");
|
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.pop();
|
||||||
L.getField(2, "z");
|
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();
|
L.pop();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int gameobjectGetPosition(psyqo::Lua L) {
|
static int gameobjectGetPosition(psyqo::Lua L) {
|
||||||
|
|
||||||
auto go = L.toUserdata<psxsplash::GameObject>(1);
|
auto go = L.toUserdata<psxsplash::GameObject>(1);
|
||||||
|
|
||||||
L.newTable();
|
L.newTable();
|
||||||
L.push(go->position.x);
|
L.pushNumber(go->position.x.raw());
|
||||||
L.setField(2, "x");
|
L.setField(2, "x");
|
||||||
L.push(go->position.y);
|
L.pushNumber(go->position.y.raw());
|
||||||
L.setField(2, "y");
|
L.setField(2, "y");
|
||||||
L.push(go->position.z);
|
L.pushNumber(go->position.z.raw());
|
||||||
L.setField(2, "z");
|
L.setField(2, "z");
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void psxsplash::Lua::Init() {
|
void psxsplash::Lua::Init() {
|
||||||
|
|||||||
12
src/lua.h
12
src/lua.h
@@ -42,13 +42,17 @@ class Lua {
|
|||||||
typedef irqus::typestring<C...> methodName;
|
typedef irqus::typestring<C...> methodName;
|
||||||
// Needs the methods table at index 1, and the script environment table at index 3
|
// Needs the methods table at index 1, and the script environment table at index 3
|
||||||
static void resolveGlobal(psyqo::Lua L) {
|
static void resolveGlobal(psyqo::Lua L) {
|
||||||
L.pushNumber(methodId);
|
// Push the method name string to access the environment table
|
||||||
|
L.push(methodName::data(), methodName::size());
|
||||||
L.getTable(3);
|
L.getTable(3);
|
||||||
|
|
||||||
if (L.isFunction(-1)) {
|
if (L.isFunction(-1)) {
|
||||||
L.push(methodName::data(), methodName::size());
|
// Store the function in methods table using numeric ID as key
|
||||||
L.setTable(1);
|
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 {
|
} else {
|
||||||
L.pop();
|
L.pop(); // Pop the non-function value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
|
|||||||
@@ -67,5 +67,5 @@ void psxsplash::SceneManager::GameTick() {
|
|||||||
static_cast<psyqo::FixedPoint<12>>(m_playerPosition.z));
|
static_cast<psyqo::FixedPoint<12>>(m_playerPosition.z));
|
||||||
m_currentCamera.SetRotation(playerRotationX, playerRotationY, playerRotationZ);
|
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
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user