Pointers to Functions
BlitzMax Forums/BlitzMax Beginners Area/Pointers to Functions
| ||
Ok, I'm stupid. How do I get the address of a function in my BMax program? Or is this not possible in this version of BMax? :< |
| ||
Global SomeFunction:Int(A:String)=MyFunction Function MyFunction:Int(A:String) Return A.ToInt() End Function Print SomeFunction("911") |
| ||
Maybe I don't quite understand, here is what I'm trying to do: Fake Code: Initialize SomeArray array or list SomeArray(0)=FirstFunctionAddress SomeArray(1)=SecondFunctionAddress SomeArray(2)=ThirdFunctionAddress SomeArray(....etc....)=OneThousandthFunctionAddress Repeat J=Random(0..somenumber) call SomeArray(J) Until some_set_condition :) This is "kinda" like what I want to do. I assume this could be put into a TList instead of an array.... So, instead of having a thousand select case, or If..else statements, I have minimal coding.... ie: faster, easier to maintain, easier to extend. These functions, of this type and for what I want to do, don't need any input, and don't need to return anything. Or am I just being stupid... I guess it could be equated to the OLD days of "ON A GOSUB 100,200,300,400,500,600...." :) |
| ||
'Create the array Global ArrayOfFunctions()[] 'Increase its size by one. ArrayOfFunctions = ArrayOfFunctions[..ArrayOfFunctions.Length + 1] 'Add the function to the array ArrayOfFunctions[ArrayOfFunctions.Length - 1] = SomeFunction 'The function that got added. Function SomeFunction() 'Code here End Function 'To call the function ArrayOfFunctions[0]() |
| ||
Thanks! Who would have known that adding the stupid "()" would fix my whole problem! Ha hah aha ah.... Duh! LOL "You know, shortcuts are nice, but make for confusion and are just EVIL......." :) One question: What type does the "Global blah()[]" get assigned too? Int??? Just curious.... |
| ||
They are function pointers. Size is probably Int I guess, I am not sure. But their type is not Int. |