"loop in gettable"?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Kingdaro
Party member
Posts: 395
Joined: Sun Jul 18, 2010 3:08 am

"loop in gettable"?

Post by Kingdaro »

I'm getting this weird error I've never seen called "loop in gettable" and I have no idea what it means or how to fix it. I'm using 32log for my game's classes and the error occurs when I make a :new() of one of these classes. And it's one of these classes specifically, the rest of them work fine.

I can't post any code right now since I'm away from my main computer, but if anyone knows the general cause of the issue, that'd be helpful. Thanks.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: "loop in gettable"?

Post by Roland_Yonaba »

I've encountered the same error, but in differents context.
And each time, that was a silly error of mine.
In the 32log thread, it seems that this error can arise, but I dunno if it was definitely fixed, though.
So, until you post your source, we cannot state anything.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: "loop in gettable"?

Post by Nixola »

I don't know what you're doing, but I can create an error like that in 3 lines of code:

Code: Select all

t = setmetatable({}, {__index = function(t, i) return u[i] end})
u = setmetatable({}, {__index = t})
print(t.dunno)
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Kingdaro
Party member
Posts: 395
Joined: Sun Jul 18, 2010 3:08 am

Re: "loop in gettable"?

Post by Kingdaro »

Roland_Yonaba wrote: So, until you post your source, we cannot state anything.
i figured. I'm home now, so here's my class:

Code: Select all

class 'Group' {
	-- define a function for adding new members
	addPart = function(self,new)
		table.insert(self.parts,new)
	end;
	
	-- the whole reason EntityGroup exists
	-- updates all of it's members with one call to the group
	-- convenience is fun.
	update = function(self,dt)
		for i,v in pairs(self.parts) do
			v:update(dt)
		end
	end;
	
	-- for every other convenient operation i could possibly want
	applyFunction = function(self,func)
		for i,v in pairs(self.parts) do
			func(i,v)
		end
	end;
	
	-- in case i don't want a member anymore
	removePart = function(self,var)
		if var.isEntity then
			-- if an entity is given to the function, search through and delete it
			-- table.remove can only use table indexes and not members
			-- i couldn't do "table.remove(self.parts,var)"
			for i,v in pairs(self.parts) do
				if v == var then
					table.remove(self.parts,i)
					break
				end
			end
		elseif type(var) == 'number' then
			-- otherwise just use the given index if it's a number.
			table.remove(self.parts,var)
		end
	end;
	
	-- because i'm lazy
	clear = function(self)
		self.parts = {}
	end;
}
i'm thinking that from Nixola's example, I'm defining a property that's indexing another class that indexes this.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: "loop in gettable"?

Post by Roland_Yonaba »

Weird. I tried the sample you provided, and calling Group:new() works actually fine.
Are we using the same version of 32log by the way?
Nixola wrote:I don't know what you're doing, but I can create an error like that in 3 lines of code:

Code: Select all

t = setmetatable({}, {__index = function(t, i) return u[i] end})
u = setmetatable({}, {__index = t})
print(t.dunno)
Err... 'loop in gettable' ? All I have here is a stack overflow, and that's actually predictable.
User avatar
Kingdaro
Party member
Posts: 395
Joined: Sun Jul 18, 2010 3:08 am

Re: "loop in gettable"?

Post by Kingdaro »

Yes, I copied the 32log library directly from the wiki.

At this point it'd probably best for me to upload a .love.
Attachments
game.love
(4.39 KiB) Downloaded 126 times
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: "loop in gettable"?

Post by Roland_Yonaba »

Okay, let's do this.
I tried your script, and I ran into the same issues.
I also tried to snag a little inside 32log source, and I found that the problem was somehow linked to these three lines inside 32log:

Code: Select all

if self.__init then
   newvalue:__init(...)
end
I tried fixing and it just brought me headaches. So I basically rewrote another light-weight and tiny OOP framework.
Let's call it 30log... Feel free to grab it, see attachment. MIT-Licensed, so do whatever you want with it.

I tested it myself, and it seems to be working fine. But, make your own checks before using it.
It features only class creation, instantiation and inheritance.
The syntax is not the same as 32log, though. Sorry for that.

Quick tour ?

Code: Select all

require '30log'

-- Class creation

myclass = class {x = 1, y = 2}
object1 = myclass:new()
object2 = myclass()
print(object1.x,object1.y) --> 1, 2
print(object2.x,object2.y) --> 1, 2


-- To create objects with specific values in a single line, implement an initialization method

myclass = class {x = 1, y = 2}
function myclass:__init(x,y)
   self.x,self.y = x,y
end

object1 = myclass:new(3,4)
object2 = myclass(3,4)
print(object1.x,object1.y) --> 3, 4
print(object2.x,object2.y) --> 3, 4


-- Inheritance:

myDerivedClass = myclass:extends {z = 3}
function myDerivedClass:__init(x,y,z)
   self.x,self.y,self.z = x,y,z
end

object3 = myDerivedClass (4.5,5.6,6.7)
print(object3.x,object3.y,object3.z) --> 4.5, 5.6, 6.7

-- adding a method to myclass
function myclass:speak(str) print(str) end
object1:speak('Object1!') --> Object1!
object2:speak('Object2!') --> Object2!
object3:speak('Object3!') --> Object3!

-- And so on with inheritance
myDerivedClass2 = myDerivedClass:extends()
object4 = myDerivedClass2()
object4:speak('Object4!') --> Object4!
If you are about to use that, pay attention to something.
When creating an object from a class, values you pass are legible if and only if you ave previously set an __init method in the class.
That is, if you want to add some extra functions/members to an object, just set the object, then use:

Code: Select all

object.member = ...
object.function (...) ... end
Attachments
30log.lua
30log.lua -- OOP Lib For Lua with class creation, instantiation and inheritance
(1.95 KiB) Downloaded 174 times
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: "loop in gettable"?

Post by Roland_Yonaba »

Double, post, to mention that I tried to tight 30log with your game.
I had to modify a bit files game.lua and class.lua, to make them compliant with the new syntax.
It seems to be running fine. See *.love file attached below.
Attachments
game.love
(6 KiB) Downloaded 113 times
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: "loop in gettable"?

Post by Nixola »

Roland_Yonaba wrote:
Nixola wrote:I don't know what you're doing, but I can create an error like that in 3 lines of code:

Code: Select all

t = setmetatable({}, {__index = function(t, i) return u[i] end})
u = setmetatable({}, {__index = t})
print(t.dunno)
Err... 'loop in gettable' ? All I have here is a stack overflow, and that's actually predictable.

Sorry, I tried to write it in 3 lines instead of the original 5, here it is:

Code: Select all

Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> t = {}
> u = {}
> setmetatable(t, {__index = u})
> setmetatable(u, {__index = t})
> print(t.duno)
stdin:1: loop in gettable
stack traceback:
        stdin:1: in main chunk
        [C]: ?
>
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Xgoff
Party member
Posts: 211
Joined: Fri Nov 19, 2010 4:20 am

Re: "loop in gettable"?

Post by Xgoff »

it's just something that happens when __index calls itself, directly or indirectly, too many times (presumably to prevent infinite recursion). there's a similar error thrown in __newindex for a similar situation

you should use rawget inside __index if an object needs to index itself inside the metamethod
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 72 guests