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

Constructing lua class and OOP.

Started by Molinko, 22 July 2014 - 09:45 PM
Molinko #1
Posted 22 July 2014 - 11:45 PM
I have been reading up on classes and oop for a while, particularly in lua, and decided to write a method to create classes for me..
Ive provided a demo below…

What are some thoughts on my approach? I know its not very unique, more like several lua tutorials smashed together.
Constructive criticisms and alternative approaches are very welcome. Thank you.

http://pastebin.com/tRspgz6B – Updated to fix messy arg var when checking parent classes. - thanks to 'theoriginalbit'
Edited on 22 July 2014 - 11:08 PM
theoriginalbit #2
Posted 23 July 2014 - 12:46 AM
Line 14, move away from arg and use {…} using arg you'll get a rogue variable n… run the following example code to see


local function foo( ... )
  for k,v in pairs(arg) do
	print(k,':',v)
  end
end

local function bar( ... )
  for k,v in pairs({...}) do
	print(k, ':', v)
  end
end

print("--foo--")
foo("hi")
print("--bar--")
bar("hi")
Edited on 22 July 2014 - 10:47 PM
Molinko #3
Posted 23 July 2014 - 01:08 AM
Line 14, move away from arg and use {…} using arg you'll get a rogue variable n… run the following example code to see


local function foo( ... )
  for k,v in pairs(arg) do
	print(k,':',v)
  end
end

local function bar( ... )
  for k,v in pairs({...}) do
	print(k, ':', v)
  end
end

print("--foo--")
foo("hi")
print("--bar--")
bar("hi")

oooo. Thank you for that. I missed it :)/> Updated per your advice…