This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
DrSpork's profile picture

[CC1.46][SSP]Metatables do not work properly through an API

Started by DrSpork, 13 November 2012 - 03:21 PM
DrSpork #1
Posted 13 November 2012 - 04:21 PM
ComputerCraft Version Information: 1.46 Client

Description of Bugs: Lua will not lookup items in metatables when the metatable is in an API

Steps to Reproduce Bug:

I was doing some work on a UI system I'm working on, which heavily uses metatables to do work. However it seems that when a file that defines a metatable is loaded as an API, and a function of that API returns a table that is a child of a metatable, the metatable is not properly used. I have a definition file (the API) that defines Panel and Panel:addComponent. Everything works fine when run from within that file, but when using it outside the API, it seems to break. To test I made a little tester program that I ran both inside and outside the API file (with the API file loaded as an API)

Inside API file (with prinouts)

p = Panel:create("The Basic Light Machine")
print(getmetatable(p))
--Table:[some numbers]
print(getmetatable(p)==Panel)
--true
print(Panel.addComponent)
--function:[some numbers]
print(p.addComponent)
--function:[some numbers]
print(Panel.components)
--Table:[some numbers]
print(p.components)
--Table:[some numbers]

Outside API file(with printouts)

p = sprkui.Panel:create("The Basic Light Machine")
print(getmetatable(p))
--table:[some numbers]
print(getmetatable(p)==sprkui.Panel)
--true
print(sprkui.Panel.addComponent)
--function:[some numbers]
print(p.addComponent)
--nil
print(sprkui.Panel.components)
--table:[some numbers]
print(p.components)
--nil

It seems to know that the metatable exists, but is never looking into it when it can't find something it the base table. Is this intended?
jag #2
Posted 13 November 2012 - 07:23 PM
I'm sorry but I don't know what a metatable is.
I looked at a wiki, but they just told me how to use it.
I wonder: what is this used for?
ElvishJerricco #3
Posted 13 November 2012 - 07:32 PM
p isn't getting its metatable set for some reason… Honestly we'd have to see a lot more of your code to diagnose the problem beyond that.
Cloudy #4
Posted 13 November 2012 - 11:36 PM
Not a bug, intended - though I may change this behavior.
Sebra #5
Posted 14 November 2012 - 03:55 AM
Why metatable contains not underscored function?
DrSpork #6
Posted 14 November 2012 - 10:01 AM
Not a bug, intended - though I may change this behavior.
OK, hopefully it gets changed,