Setup
- MacOS 12.5
- PlayDate Simulator Version 1.12.2 (139389)
- pdc version 1.12.2
Project
I have a single source
directory with 3 files in it:
source/my_class.lua
import "CoreLibs/object"
class("MyClass").extends()
function MyClass:init()
end
function MyClass:hello()
print("Hello from MyClass!")
end
source/my_class2.lua
import "CoreLibs/object"
class("MyClass2").extends()
function MyClass2:init()
end
function MyClass2:hello()
print("Hello from MyClass2!")
end
source/main.lua
import "CoreLibs/object"
import "my_class"
import "my_class2"
local my = MyClass()
local my2 = MyClass2()
(function()
my:hello()
my2:hello()
end)()
function playdate.update()
end
I can successfully compile the project using pdc source output.pdx
.
Expected behaviour
Two hello messages in the console, printed once.
Actual behaviour
Error message when output.pdx
is opened in the simulator:
main.lua:7: attempt to call a table value
stack traceback:
main.lua:7: in main chunk
main.lua:7: attempt to call a table value
stack traceback:
main.lua:7: in main chunk
Theory
The problem seems to be unrelated to the error message from the simulator. If I replace the anonymous init function with an proper function definition followed by a function call, the expected behaviour is observed.
function init()
my:hello()
my2:hello()
end
init()
Would appreciate any help uncovering this mystery!