lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Just like you are doing, except without the first set of () around do_cmd1,
etc.

So, just to be clear:

function foo()
-- do something
end

myTable = { foofunc = foo,
 		barfunc = function ()
				-- do something else
			    end
	    }

myTable now has two "function pointers" that you can use like this:

local a = myTable.foofunc
local result = a()
local b = myTable.barfunc
local result2 = b()

Eric

> -----Original Message-----
> From: owner-lua-l@tecgraf.puc-rio.br
> [mailto:owner-lua-l@tecgraf.puc-rio.br]On Behalf Of John S. Miley
> Sent: Thursday, November 15, 2001 9:25 PM
> To: Multiple recipients of list
> Subject: Function Pointers?
>
>
>
> How would I go about emulating function pointers in lua?  Basically, what
> I'm trying to accomplish is something like:
>
> gCmdList = {
> 	cmd1 = do_cmd1(),
> 	cmd2 = do_cmd2(),
> 	...
> }
>
> gObj1 = {
> 	[properties]
> 	lCmdList = {
> 		cmd3 = do_cmd3(),
> 		cmd4 = do_cmd4(),
> 		...
> 	}
> }
>
> gObj2 = {
> 	[properties]
> 	lCmdList = {
> 		cmd5 = do_cmd5(),
> 		cmd6 = do_cmd6(),
> 		...
> 	}
> }
>
> function do_cmd1()
> 	block
> end
>
> function do_cmd2()
> 	block
> end
>
> function gObj1:do_cmd3()
> 	block
> end
>
> function gObj1:do_cmd4()
> 	block
> end
>
> function gObj2:do_cmd5()
> 	block
> end
>
> function gObj2:do_cmd6()
> 	block
> end
>
>
> Thanks,
>
> --jsm
>
>
>