Using a function pointer of some sort is it possible to pass a procedure as a parameter to another procedure?
If one of these function pointers was passed, how can I call it and pass it parameters?
Passing a procedure as a param to another procedure
Passing a procedure as a param to another procedure
Paul Dwyer
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
- NicTheQuick
- Addict
- Posts: 1226
- Joined: Sun Jun 22, 2003 7:43 pm
- Location: Germany, Saarbrücken
- Contact:
Re: Passing a procedure as a param to another procedure
You can use CallFunctionFast() which is a very low level way to call procedures and only works good with integer arguments. Or you can use Prototypes for that.
Code: Select all
Prototype.i calc(a.i, b.i)
Procedure.i add(a.i, b.i)
ProcedureReturn a + b
EndProcedure
Procedure.i sub(a.i, b.i)
ProcedureReturn a - b
EndProcedure
Procedure.i execute(*proc.calc, a.i, b.i)
ProcedureReturn *proc(a, b)
EndProcedure
Debug execute(@add(), 1, 2)
Debug execute(@sub(), 1, 2)
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
Re: Passing a procedure as a param to another procedure
You have to define a Prototype of your procedure which you want to pass:
Code: Select all
Prototype.f Operation(Param1.f, Param2.f) ; Definition of the passed procedure
Procedure DoIt(Func.Operation, Value1.f, Value2.f) ; Just define the procedure parameter as a prototype
ProcedureReturn Func(Value1, Value2)
EndProcedure
;- Example
Procedure.f Add(A.f, B.f)
ProcedureReturn A+B
EndProcedure
Procedure.f Mul(A.f, B.f)
ProcedureReturn A*B
EndProcedure
Debug DoIt(@Add(), 3, 4)
Debug DoIt(@Mul(), 3, 4)
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Re: Passing a procedure as a param to another procedure
Thankyou !!! I'll look into this!
Very helpful
Very helpful
Paul Dwyer
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein