Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method on table fails to modify table state #16

Closed
jeff-emanuel opened this issue Oct 23, 2018 · 4 comments
Closed

Method on table fails to modify table state #16

jeff-emanuel opened this issue Oct 23, 2018 · 4 comments

Comments

@jeff-emanuel
Copy link

The following code does not change buffer as it does in Lua 5.3.4:

obj = { buffer = {} }
function obj.append(self,value) self.buffer[#self.buffer+1] = value end
obj:append(7)
print(#obj.buffer)
for i,v in ipairs(obj.buffer) do print(i,v) end

It also does not work when passing an explicit self parameter:

obj = { buffer = {} }
function obj.append(self,value) self.buffer[#self.buffer+1] = value end
obj.append(obj,7)
print(#obj.buffer)
for i,v in ipairs(obj.buffer) do print(i,v) end

The attached code prints 0 twice.

luamethod.zip

@milochristiansen
Copy link
Owner

Initial testing indicates a compiler error, as code compiled with luac works properly. I still need to identify where it is going wrong, but a fix should be available within the day.

@jeff-emanuel
Copy link
Author

jeff-emanuel commented Oct 23, 2018 via email

@milochristiansen
Copy link
Owner

Ok, the problem was pretty obvious once I thought to examine the object with pairs instead of ipairs. Turns out the compiler was using the same register for both key and value.

The issue was caused by the code that compiled identifiers not properly indicating how many registers it used in certain cases. I'll push the fix in the next minute or so. Hopefully it fixes all such cases, but if not let me know.

@jeff-emanuel
Copy link
Author

Thanks again for the prompt response. It looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants