class Neuron; typedef vector<Neuron> Layer;
Neuron and Layer are both classes.
The original code is here.
Posted 07 October 2015 - 04:01 PM
Posted 07 October 2015 - 04:07 PM
Posted 07 October 2015 - 04:31 PM
local Neuron
Posted 07 October 2015 - 04:34 PM
Posted 07 October 2015 - 04:44 PM
--#creating an object
obj = {}
obj.data = "this is a string"
function obj.m1(self, ...) --#here we use the self as lua won't set it for us, we could call it anything else. For compatibility the object is the first parameter
print(self.data) --#self.data is the same as obj.data as self is obj
end
function obj:m2(...) --#here we used a colon instead of a dot, this means that Lua will make the self variable for us. The object is the first parameter but Lua is adding that in for us
print(self.data)
end
--#calling object methods
--#both of the above methods do the same thing in nearly the same way (the colon is shorthand for us, and will be again)
obj.m1(obj) --#we used a dot so we have to pass the obj table so that the object knows what it is
obj:m1() --#this time we use a colon so lua is passing the table without us having to do so.
obj:m1(obj) --#we just passed obj twice (with lua doing it first), while this may not cause problems with the method, it probably is not what we want to do
obj.m2(obj)--#back to using dot just to prove that both calls work with both functions
obj:m2() --#colon works here too
Edited by Lupus590, 07 October 2015 - 04:45 PM.
Posted 07 October 2015 - 05:37 PM
Posted 07 October 2015 - 06:28 PM
Posted 08 October 2015 - 05:38 PM
Lupus590, on 07 October 2015 - 06:28 PM, said:
0 members, 1 guests, 0 anonymous users