Some libraries need to use user callBacks.Native convention for XBlite is STDCall but some of theses library request CCall conventions in their callbacks (NEWTON,LUA,etc...)
Hopefully, Xblite owns inline ASM so nothing is lost, this is just a little trick that does the job.
First, write your function normaly and compile (F9 only, don't build).
Look at yourprogram.asm and check for your function end (use search because ASM code is very very very very (and so on) long).It looks like this :
Quoted Text
end.SV_NEWTON_RaycastNOTfilter.mye2: ;;; Function end label for Assembly Programmers.
end.func117.mye2:
lea esp,[ebp-20] ;;; i110
pop ebx ;;; restore ebx
pop edi ;;; restore edi
pop esi ;;; restore esi
leave ;;; replaces 'mov esp,ebp' 'pop ebp'
ret 20 ;;; i111a
So just copy asm code and remove the number after 'ret' (in fact it removes arguments from stack but in CCall, caller removes the arguments so that unbalance the stack)
And when your funcs returns a value ?
This is simple, if it is an integer, return the value on EAX, if it is a float, return on ST0.You can use a local variable to write the value and load it into EAX or ST0 after.Example :
FUNCTION SINGLE DoSomething(a,b,c,d)
SINGLE float
float=1.25!
ASM fld d[DoSomething.float]
(copy here ASM code like i wrotte before)
If you use some standarts values, this is a shortcut
Quoted Text
FLD1 Push +1.0 onto the FPU register stack.
FLDL2T Push log210 onto the FPU register stack.
FLDL2E Push log2e onto the FPU register stack.
FLDPI Push p onto the FPU register stack.
FLDLG2 Push log102 onto the FPU register stack.
FLDLN2 Push loge2 onto the FPU register stack.
FLDZ Push +0.0 onto the FPU register stack.
Easy Assembler Shell v3.99 Copyright(C) 1999 Roman Novgorodov
For integers, this is the same methods execpt you must use EAX
A complete real example, a callback filter for raycasting in NEWTON :
Quoted Text
'
' ########################################
' ##### SV_NEWTON_RaycastNOTfilter #####
' ########################################
'
'will stop hit on first body except body that initiate raycast
'
FUNCTION SINGLE SV_NEWTON_RaycastNOTfilter (body,CVector3 normal,collision,from_body,SINGLE param)
SHARED SERVER_INFO ServerI
IF body=from_body THEN
ASM fld d[SV_NEWTON_RaycastNOTfilter.param]
ELSE
ServerI.rayCastResult=body
ASM fldz
ENDIF
ASM lea esp,[ebp-20]
ASM pop ebx
ASM pop edi
ASM pop esi
ASM leave
ASM ret
END FUNCTION
I hope this could be usefull to someone else.