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

Something I've been wondering about.

Started by Dlcruz129, 07 February 2013 - 05:31 PM
Dlcruz129 #1
Posted 07 February 2013 - 06:31 PM
So, lets say I have the following code:
function makeTable(name)
  name = {}
end

Wouldn't this create a table named "name"? How would I be able to make a function like this? I see no real use for this, but I'm just curious.
tesla1889 #2
Posted 07 February 2013 - 06:34 PM
there is no use

i suppose if you were almost out of memory, it would cause an error

because the table's an upvalue (variable in function declaration), it will be garbagecollected every time you call the function
Dlcruz129 #3
Posted 07 February 2013 - 06:37 PM
there is no use

i suppose if you were almost out of memory, it would cause an error

because the table's an upvalue (variable in function declaration), it will be garbagecollected every time you call the function

Er, doesn't quite answer the question.
remiX #4
Posted 07 February 2013 - 06:46 PM
It's easier to type

Tab = {}

…?
tesla1889 #5
Posted 07 February 2013 - 06:48 PM
all it would do is just ignore what ever was passed to it, create a table, then garbagecollect it
LBPHacker #6
Posted 07 February 2013 - 10:37 PM

function makeTable(name)
    _G[name] = {}
end

makeTable("myTable")
print(type(myTable)) -- this'll print "table"

Why not?
Dlcruz129 #7
Posted 08 February 2013 - 04:11 AM

function makeTable(name)
    _G[name] = {}
end

makeTable("myTable")
print(type(myTable)) -- this'll print "table"

Why not?

Thanks for actually answering the question.