Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


LUA/luabind : attempt to index global 'self' (a nil value)


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 carmellose   Members   -  Reputation: 122

Like
0Likes
Like

Posted 19 March 2009 - 05:52 AM

hi guys,

i'm begining LUA with (luabind for c++ bindings) and it seems i didn't understood something, because when i try to declare a class with tables inside, i have a strange error.

basically, i have a class declared like:

class 'scheduler'
--
function scheduler:__init(agents)
	print("[+] new scheduler instance ...")
	self.agentsCoroutines = {}
	self.writesQueue = {}
	for i,j in pairs(agents) do
	table.insert(self.agentsCoroutines, {
										coroutine.create(agents[i][1]), 
										agents[i][2] --[[channel--]]} )
	print(self.agentsCoroutines[i],"status:",coroutine.status(self.agentsCoroutines[i][1]) )
	end
	return self
end





this works, albeit when i declare this:

function scheduler.start()
	local myThread = self.agentsCoroutines
end





i have this strange error:

Quote:

attempt to index global 'self' (a nil value)


do you know what i'm having wrong??

thank you in advance

Sponsor:

#2 Giedrius   Members   -  Reputation: 164

Like
0Likes
Like

Posted 19 March 2009 - 06:08 AM

function scheduler.start() should be function scheduler:start(), with a : instead of a .

#3 carmellose   Members   -  Reputation: 122

Like
0Likes
Like

Posted 19 March 2009 - 09:18 AM

Quote:
Original post by Giedrius
function scheduler.start() should be function scheduler:start(), with a : instead of a .


hi
i've tryed it but i still have the same problem :/

#4 carmellose   Members   -  Reputation: 122

Like
0Likes
Like

Posted 19 March 2009 - 09:47 PM

up

#5 ddn3   Members   -  Reputation: 1309

Like
0Likes
Like

Posted 20 March 2009 - 09:17 AM

post your class definition for the scheduler, it should be something like this:



scheduler = { } -- Create a table to hold the class methods
function scheduler:new() -- The constructor
local object = {
mMemebers=nil,
}
setmetatable(object, {
-- Overload the index event so that fields not present within the object are
-- looked up in the prototype parent class table
__index = scheduler
})
return object
end

function scheduler:start()
local myThread = self.agentsCoroutines
end




The idea of programming OO in Lua is to create a instance of a table with the approraite __index methamethod to allow access to the methods of that class.

You create the scheduler instance using some function similar to the :new() from above. Like so :

local instance = scheduler:new();

now the self parameter is valid for the given instance, otherwise calling the function of scheduler will not have any valid self parameter, whether u use the : or . notation.

now you can do something like..

instance:start();

There isn't enough information from the scheduler class to give you any clear answers.

Good Luck!

-ddn





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS