ah, ok. there seems something not to work as I wish it would... I repost the changed script here - the line which makes it crash is commented (line-number 42) - oh what coincidence... perhaps I have made something wrong in line 61 with that * ?
Problem seems to be that the pointers of a string-array are not there where I thought they would be. Straight in a row of Dwords starting at DataPtr...
Uses "oxygen", "console"
Alias Long As FunctionPtr
FunctionPtr P_O2End, P_GetPtr
If Not run_O2() Then
PrintL "error within O2-script - can not run this"
PrintL O2_ERROR
WaitKey
Stop
EndIf
Declare Sub finish() At P_O2End
Declare Function GetPtr(ByVal String, Optional ByVal Long, Optional ByVal Long) As DWord At P_GetPtr
' some testing:
Long foo = 123
DWord myPtr = GetPtr("foo")
PrintL "foo = " + CVL(Memory_Get(myPtr, SizeOf(Long)))
Dim dog(123) As Byte
dog(42) = 42
myPtr = GetPtr("dog", 42, SizeOf(Byte))
Dim olk(77) As Double
olk(33) = CVBYT(Memory_Get(myPtr, SizeOf(Byte))) + 0.125
PrintL "olk(33) = " + CVD(Memory_Get(GetPtr("olk", 33, SizeOf(Double)), SizeOf(Double)))
String test = "I am an important string"
myPtr = GetPtr("test")
PrintL "memory found:"
PrintL Memory_Get(myPtr, Peek(DWord, myPtr - 4))
Dim s2(5) As String = "wrong", "wrong", "right", "wrong", "wrong"
myPtr = GetPtr("s2", 3)
PrintL "memory found:"
' This crashes >>> PrintL Memory_Get(myPtr, Peek(DWord, myPtr - 4))
WaitKey
finish()
'----------------------------------------------
Function run_O2() As Boolean
Local src As String = "
#basic
include "thincore.inc"
Function GetPtr(Byval sName as String, Optional ByVal Index as Long, Optional Byval lSize as Long) As Dword link #P_GetPtr
long MainType, SubType, IsArray, DataPtr, nElements
thinBasic_VariableGetInfoEX(sName, MainType, SubType, IsArray, DataPtr, nElements)
If Index > 0 And Index <= nElements then
If MainType = 30 Then ' string
' print "String Array Check"
Function = *(DataPtr + (Index-1) * SizeOf(Dword))
Else
Function = DataPtr + (Index - 1) * lSize
EndIf
Else
If MainType = 30 Then ' string
Function = *DataPtr
Else
Function = DataPtr
EndIf
EndIf
End Function
'------------------------------------------
Sub finish() link #P_O2End
terminate
End Sub
"
O2_BASIC src
If O2_ERROR <> "" Then Return FALSE
O2_EXEC
Function = TRUE
End Function
and I still don't know how I could place some dword-array [nElements] at DataPtr - anyhow I try - error
dword sPtrs[nElements] at DataPtr - error invalid constant autodim,
the method in line 61 is not correct - I tested the result from thinBasic where I can find the Stringpointers in order as awaited and it returns wrong values.
Bookmarks