Jump to content




Calling a function from a table


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

#1 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 23 April 2014 - 09:45 PM

Stuff[1] = coroutine.resume()

Stuff[1]
'=' expected.

Is there any way of doing something similar to this, executing a line stored in a table?

#2 CometWolf

  • Members
  • 1,283 posts

Posted 23 April 2014 - 09:50 PM

Stuff[1]()
It's a function pointer like any other, why would calling it be any different? :P

Note that this
Stuff[1] = coroutine.resume()
would store the result of coroutine.resume() in your table, not the function iself.

Edited by CometWolf, 23 April 2014 - 09:51 PM.


#3 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 23 April 2014 - 09:59 PM

Ok, I get that, but I can't use that in my program (see spoiler). Any ideas on how to do this? *note: this code is definitely full of bugs, because while trying to debug I ran into this error.


Spoiler


#4 CometWolf

  • Members
  • 1,283 posts

Posted 23 April 2014 - 10:12 PM

This
local bcontact = newButton(10, 20, 5, 10, "New Contact", colors.lime, colors.red, coroutine.resume(newContact))
won't work as intended. Same as above, your passing the results of coroutine.resume(newContact), not the function itself.
Use an anonymous function if you wish to pass a function with parameters.
local bcontact = newButton(10, 20, 5, 10, "New Contact", colors.lime, colors.red, function() coroutine.resume(newContact) end)






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users