Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Questions about lua — Gideros Forum

Questions about lua

olegoleg Member
edited August 2019 in Code snippets
Sorry for the baby question:
How to check that the table has a function? So far I have found a way out:if #a[1]==0 , Is it possible to do it differently?
	function test()
		print ("test1")
	end
 
    a={{p=test},234523}
 
	for i=1,2 do
		if #a[i]==0 then
			a[i].p()
		else 
			print(a[i])
		end
 
	end
my games:
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!

Comments

  • olegoleg Member
    solved the problem:
    	function test()
    		print ("test1")
    	end
     
        a={{test},0}
     
    		if type(a[1])=="table" then
    			a[1][1]()
     
    		end

    Likes: Apollo14

    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
    +1 -1 (+1 / -0 )Share on Facebook
  • hgy29hgy29 Maintainer
    Accepted Answer
    why not just test for a function ?
    function test()
    		print ("test1")
    	end
     
        a={test,0}
     
    		if type(a[1])=="function" then
    			a[1]()
    		end

    Likes: oleg

    +1 -1 (+1 / -0 )Share on Facebook
  • olegoleg Member
    edited August 2019
    hgy29 said:

    why not just test for a function ?

    Because I need to pass parameters to the function
    	function test(param)
    		print ("test1",param)
    	end
     
        a={{test,23},0}
     
    		if type(a[1])=="table" then
    			a[1][1](a[1][2])
     
    		end
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
Sign In or Register to comment.