I am implementing support for external modules. You will be able to write static libraries in C and link them to the NextBasic program, but the compiler needs to know that these functions exist so when you use them in your program they won't throw a compiler error.
The core NextBasic functions that I blogged about int the last post will be placed in a "core" module that is automatically included in all your programs. Inside NextBasic's "modules" folder, there will be a folder named "core" with the files "core.nb", "libcore.win32.a", "libcore.linux32.a" and "libcore.mac.a". An excerpt from the file "core.nb" looks as follows (with only the Array functions to not make the example too big):
$Link "core"
Extern
Function CreateArray%()
Function FreeArray(arr)
Function CountArray%(arr)
Function ArrayAddInt(arr, i)
Function ArrayAddFloat(arr, f#)
Function ArrayAddString(arr, s$)
Function ArrayAddObject(arr, obj As Struct)
Function ArraySetInt(arr, index, i)
Function ArraySetFloat(arr, index, f#)
Function ArraySetString(arr, index, s$)
Function ArraySetObject(arr, index, obj As Struct)
Function ArrayGetInt%(arr, index)
Function ArrayGetFloat#(arr, index)
Function ArrayGetString$(arr, index)
Function ArrayGetObject(arr, index) As Struct
Function ArrayRemoveAt(arr, index)
Function ArrayRemoveObject(arr, obj As Struct)
Function ArrayClear(arr)
EndExtern
The first line indicates the preprocessor that the static library "core" needs to be linked to our program. It will pick the correct name based on the platform we are compiling for (for example, on Windows it would be "libcore.win32.a"). After that,we declare an "Extern" block, which indicates that the functions we are going to declare within the block do not have a function body, because it is contained in an external library.
One thing to note is that "Struct" is a valid type for arguments and functions. It indicates that any variable which is of a user defined type will be a valid parameter, and that we can assign the return value to any of these variables (so you have to make sure that you are assigning it to the correct type). This allows NextBasic to put any kind of user defined var inside an array.
No hay comentarios:
Publicar un comentario