Jump to content




Something I've been wondering about.


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

#1 Dlcruz129

    What's a Lua?

  • Members
  • 1,423 posts

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.

#2 tesla1889

  • Members
  • 351 posts
  • LocationSt. Petersburg

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

#3 Dlcruz129

    What's a Lua?

  • Members
  • 1,423 posts

Posted 07 February 2013 - 06:37 PM

View Posttesla1889, on 07 February 2013 - 06:34 PM, said:

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.

#4 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 07 February 2013 - 06:46 PM

It's easier to type

Tab = {}

...?

#5 tesla1889

  • Members
  • 351 posts
  • LocationSt. Petersburg

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

#6 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 07 February 2013 - 10:37 PM

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

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

Why not?

#7 Dlcruz129

    What's a Lua?

  • Members
  • 1,423 posts

Posted 08 February 2013 - 04:11 AM

View PostLBPHacker, on 07 February 2013 - 10:37 PM, said:

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

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

Why not?

Thanks for actually answering the question.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users