c - Guides for implementing a foreign function interface -


I am currently working on a scripting language that has no FFI yet. I want to know what is the most convenient way to get it, assuming that I want to write it like a quiet Geek - I want to write FFI only in the scripting language.

The programming language for me is C for the interface. C. For the original I know that libdl.so is my best friend. Obviously this is not the only thing needed, but the most important thing of them is.

I only have a few thoughts about it, what else do I need for it? I want to treat FII the same way that the Dragon is with CTIP.

What do I need to know to get it so far? I know that there is some serious magic with data structures, I'll need to deal with it. How can I manage it so that I can make the biggest of that serious magic in scripting language? I used to use this kind of magic more than just foreign function interfaces. For example, I would like to send the c-binary data to the file.

I think an appro hit answer is needed.

Basically, the library provided by the host OS should be a wrapper for the loading and symbol search feature. If the main datatyme of your language is internally presented with a C data structure, then a requirement can be placed on library developers that the parameters of the Export C functions and the return types should be the objects of that data structure. This will simplify the data exchange to be implemented. If there are some pattern expressions and first-class functions in your language, then the signature pattern of the C function can be written in and the library can be searched for a function matching the equivalent signature. Here are some of the pseudo-scales and scripts in the C function:

  / * arith.dll * / / * A sample C function right from the scripting language. * / #include "my_script.h" // Script structure used by interpreter My_Script_Object * add (My_Script_Object * num1, My_Script_Object * num2) {int a = My_Script_Object_To_Int (num1); Int b = My_Script_Object_To_Int (num2); Return Int_To_My_Script_Object (a + b); } / * End of Arith.dll * / // script using dll clib = open_library ("arith.dll"); // if there are first-class functions in this add_func = clib.find ([int int add]); If (cfunc! = Null) {sum = add_func (10, 20); Print (amount); } // Print otherwise (clib.call ("add", 10 20));  

It is not possible to discuss more implementation details here. Note that we have not said anything about garbage collection etc.

The available resources at the following link can help you move forward:


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -