nielsAD / lape

Scripting engine with Pascal-like syntax for FPC and Delphi
119 stars 28 forks source link

Reuse FFI closures #133

Closed ollydev closed 5 years ago

ollydev commented 5 years ago

Every call you would get a new method address so the something like the following didn't work:

addHandler(@foo);
removeHandler(@foo);

Perhaps not the prettiest way, but you get a static address now.

TaylorSwiftIsQueenButNobodyWillSeeThis

nielsAD commented 5 years ago

This will fail when you try to create a closure for the same pointer twice but with a different header. Not only different calling convention, but different parameters might cause issues as well. I think in practice, every valid header with the same calling convention will pass parameters the same way under the hood, but invalid headers (after a type cast for example) might cause issues for future FFI closures.