Skip to content

Commit 08d07c0

Browse files
authored
Better constructor for Lua FixedPoint.
1 parent 457e1e7 commit 08d07c0

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/mips/psyqo-lua/src/lua.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static constexpr char PSYQO_FIXEDPOINT_METATABLE[] = "psyqo.FixedPoint";
4646
void psyqo::Lua::push(FixedPoint<> fp) {
4747
// Get the FixedPoint constructor from registry
4848
getMetatable(PSYQO_FIXEDPOINT_METATABLE);
49-
getField(-1, "new");
49+
getField(-1, "newFromRaw");
5050
pushNumber(fp.raw());
5151
call(1, 1); // Create new FixedPoint table
5252
remove(-2); // Remove metatable from stack
@@ -329,9 +329,15 @@ void psyqo::Lua::setupFixedPointMetatable() {
329329
end
330330
331331
-- Create a new FixedPoint from raw value
332-
function FixedPoint.new(raw_value)
332+
function FixedPoint.newFromRaw(raw_value)
333333
return setmetatable({_raw = raw_value}, FixedPoint)
334334
end
335+
336+
-- Create a new FixedPoint
337+
function FixedPoint.new(integer, fraction)
338+
if fraction == nil then fraction = 0 end
339+
return setmetatable({_raw = bit.lshift(integer, 12) + fraction}, FixedPoint)
340+
end
335341
end
336342
)lua";
337343

0 commit comments

Comments
 (0)