Function as parameters
BlitzMax Forums/BlitzMax Programming/Function as parameters
| ||
I'm trying to wrap a function as parameter in cpp and have no idea what I'm doing. This thread shows how to pass function as parameter but what if the function is in cpp? In cpp: void FluidFunction(Fluid* fluid, float (*FieldFunction)(float, float, float)){ fluid->FluidFunction(FieldFunction); } void Fluid::FluidFunction(float (*FieldFunction)(float, float, float)){ ScalarField=FieldFunction; } I have this, which I know is wrong: Function FluidFunction_( fluid:Byte Ptr, FieldFunction:Float( Float, Float, Float ) ) = "FluidFunction" Function FluidFunction( fluid:TFluid, FieldFunction:Float( Float, Float, Float ) ) FluidFunction_( TUtility.IsObject( fluid ), FieldFunction ) End Function |
| ||
You have to give the parameters to the function pointer names, for some reason:Function FluidFunction_( fluid:Byte Ptr, FieldFunction:Float( _0:Float, _1:Float, _2:Float ) ) = "FluidFunction" Function FluidFunction( fluid:TFluid, FieldFunction:Float( _0:Float, _1:Float, _2:Float ) ) FluidFunction_( TUtility.IsObject( fluid ), FieldFunction ) End Function It doesn't matter what the names are. They won't be read by anything, it just doesn't seem to know how to parse types on their own. Other than that... looks fine. C++ part looks OK. |
| ||
Thanks! It compiles but I haven't tested the function yet. Good to know this is so straight-forward. |