' function to import
Function MySuperPrint( s:Byte Ptr)
Print String.FromCString( s)
EndFunction
' import function
newlispEvalStr( "(importfn {mysuperprint} " + Int(MySuperPrint) + ")")
' call function
newlispEcalStr( "(mysuperprint {Hello World})")
it works the same in any other language, like vb,c,pascal etc.
and it saves me from creating a seperate dll with support functions.
quite handy for using newlisp as an embedded scripting language =)
Last edited by grable on Thu Jun 16, 2005 12:20 pm, edited 1 time in total.
I own a Blitz3D license and was waiting that Blitzmax get the same powerfull features in 3D as it's DirectX brother. All what I read on the forums there about Blitzmax and your news here will raise my interest in the new member of the blitz family.
I hope Lutz will add this feature to the distribution.
This can already be done using exisiting newLISP functions. Earlier this month I posted a method how to execute binary content embedded in a newLISP program (sorry can't find the pointer to this at the moment).
A similar method could be used to import a function pointer:
; get a template cell from any built-in function
(set 'foo print)
; change to a library function use 265 'stdcall', or 264 for 'cdecl'
(cpymem (pack "ld" 265) (first (dump foo)) 4)
; copy the function address
(cpymem (pack "ld" func-address) (+ (first (dump foo)) 12) 4)
Grable will immedeately understand what we are doing here, the newLISP code pretty much replicates his C-code. In the second step use 265 for standard Win32 calling conventions and use 264 for 'cdecl' 'C'-calling conventions.
After the 3 statements do a (dump MySuperPrint) to make sure type value and function address are in their places