calling the function|subroutine by its ptr, i see.
Something i saw in oxygen but don't remember where it was and what was the exact syntax but i am certain it was oxygen, it was like
Function f() as Int
{
Dim Int result At @f
'...
result = 42
}
was it really that simple ? is the function-pointer also the pointer where to read or write the result?
Ans omething that annys me now for a while and i don't know why:
I am passing parameters BYVAL to a function - i tried already to use CAST and lots more- and usually BYVAL can not be parameter type mismatch
but it keeps complaining i would pass double - even i dont.
Same is when i use Extended type as function parameters - it always complains about DOUBLE and parameter type mismatches.
I just post the script.
The bugging line is 63, (### marked ###) but as you see in StrRight at the same position where i used ABS it is the same . Actually i would prefer to use the limit- functions without the need to cast for integer types mainly - and to return also integers without the need to cast parameters nor results
$ filename "teststr.exe"
$ CRLF chr(13) chr(10)
$ DQ chr(34)
Function StrLen(byref s as bstring) as dword
===================================
dim dword dwLen at strPtr s
if @dwLen then
dword dwLen at (strptr s) - 4
Function = dwLen
end if
end function
function InLimits(byval nX as int, byval nMin as int, byval nMax as int) as boolean
' should tell if numberX is within limits nMin and nMax (inclusive)
if nX < nMin then return false
if nX > nMax then return false
function = true
end function
function SetLimits(byval nX as int, byval nMin as int, byval nMax as int) as int
' should return number nX limited between nMin and nMax if outside that range
if nX < nMin then return nMin
if nX > nMax then return nMax
function = nX
end function
------------------------------------
function StrLeft(byref sX as Bstring,
byval numbytes as int) as bstring
=============================================================
' get the left part (in bytes count ) passed through lbytLen
' e.g. assumed sX ="1234567890"
' when lbytLen is a:
' value > 0 but <= len(sX) it works as Left(sX, lbytLen)
' e.g. assumed lbytLen = 3 returned is "123"
' Value < 0 but abs(lbytLen) <= len(s) it works as Left(s, Len(s)-lbytLen):
' e.g. assumed lbytLen = -3, returns "1234567"
' StrRight works exactly opposing to StrLeft
static sResult as bstring
dim dword dwLen at strPtr sX
if @dwLen then
dword dwLen at (strptr sX) - 4
'# # # # # # #
if inLimits( sgn(numbytes) * numBytes, 1, dwLen ) then
'# # # # # # #
if numBytes < 0 then
numBytes = dwLen + numbytes
sResult = String(numBytes, chr(0))
copy strPtr sResult, strPtr sX, numBytes
else
sResult = String(numBytes, chr(0))
copy strptr sResult, strptr sX, numBytes
endif
endif
endif
function = sResult
end function
-------------------------------------------
function StrRight(byref sX as Bstring,
byval numbytes as int) as bstring
=============================================================
' get the right part of sX
' e.g. assumed sX ="1234567890"
' when
' numbytes > 0 and <= len(s) it works as Right(s, numbytes)
' e.g. assumed numbytes = 3, returns "890"
' numbytes < 0 and abs(numbytes) <= len(s) it works as Right(sX, Len(sX)+numbytes)
' e.g. assumed numbytes=-3, returns "4567890"
' StrRight works exactly opposing to StrLeft
dim sResult as bstring
dim dword dwLen at strPtr sX
if @dwLen then
dword dwLen at (strptr sX) - 4
'# # # # # # #
if inLimits(abs numBytes, 1, dwLen ) then
'# # # # # # #
if numBytes < 0 then
sResult = String(dwLen + numBytes, chr(0))
copy strPtr sResult, (strPtr sX)+abs(numBytes), dwLen + numBytes
else
sResult = String(numBytes, chr(0))
copy strptr sResult, (strptr sX) + dwLen - numBytes, numBytes
endif
endif
endif
function = sResult
end function
dim x1, x2, x3, xx as bstring
x1 = "A b c d e f g h i j k l m n o p q r s t u v w x y z"
x2= strLeft x1, 20
x3= strLeft x1,-10
xx = "String " DQ x1 DQ CRLF Str(strLen x1) " bytes of length" crlf
xx &= "StrLeft s, 20 = " DQ x2 DQ str(StrLen x2) " bytes" crlf
xx &= "StrLeft s,-10 = " DQ x3 DQ str(StrLen x3) " bytes" crlf
x2= strRight x1, 20
x3= strRight x1,-10
xx &= "StrRight s, 20 = " dq x2 DQ str(strlen x2) " bytes" crlf
xx &= "StrRight s, -10 = " dq x3 DQ str(strlen x3) " bytes" crlf
print xx
btw. are bStrings the default ? can i also peek a dword in front of a "String"-string without to risk a gpf?
Bookmarks