View Full Version : How to parse BYREF?
Michael Hartlef
06-10-2007, 17:46
Hi folks,
I know that you can set the value of parameter variables but I don't know how.
Petr does this in the TBGL module. Can you show a little example?
Thanks in advance
Michael
Michael Hartlef
06-10-2007, 17:51
Here is the sub where I want to use this:
'**************************************************************************************************
SUB GetNodeXYZ(),DOUBLE
'**************************************************************************************************
DEF id,cid:INT
DEF i:INT
DEF posx,posy,posz : DOUBLE
IF thinBasic_CheckOpenParens(FALSE, FALSE)
id = thinBasic_ParseDword()
IF thinBasic_CheckComma()
posX = thinBasic_ParseDouble()
IF thinBasic_CheckComma()
posY = thinBasic_ParseDouble()
IF thinBasic_CheckComma()
posZ = thinBasic_ParseDouble()
IF thinBasic_CheckCloseParens(FALSE, FALSE)
i = id
FOR tempData = EACH nodeList
IF #<NodePoint>tempData.ID = i
posx = #<NodePoint>tempData.xpos
posy = #<NodePoint>tempData.ypos
posz = #<NodePoint>tempData.zpos
GOTO lFinish232
ENDIF
NEXT
ENDIF
endif
endif
endif
ENDIF
RETURN thinbasic_TRUE
ENDSUB
Michael Clease
06-10-2007, 18:09
are you saying that you want to directly access the memory locations of posx,posy,posz because I dont see any way that thinbasic can pass pointers for IBASIC.
I dont use IB so this is a quick observation so I could be wrong.
ErosOlmi
06-10-2007, 18:24
Mike,
I'm sorry but there is no direct interface for IBasic at the moment. Under IBasic SDK we just exposes a little subset of the many interfaces we have developed and usable under PowerBasic. But if you are interested, I think we can quite easily develop them in a short time.
In details, there are some functions do achieve the job. Those are the templates under Power Basic that we can release also under IBasic. One of the most important is thinBasic_VariableParse function that will perform all the checks and return a pointer to the variable internal descriptor plus the element number in case of an array.
'----------------------------------------------------------------------------
'thinBasic_VariableParse
'----------------------------------------------------------------------------
' Instruct parser to get next token, check if variable, check if array and
' return all info needed to subsequent change variable value
'----------------------------------------------------------------------------
DECLARE FUNCTION thinBasic_VariableParse _
LIB "thinCore.DLL" _
ALIAS "thinBasic_VariableParse" _
( _
BYREF VariablePtr AS LONG , _ '---ATTENTION: parameter passed BYREF will return info
BYREF VariableAbsPos AS LONG _ '---ATTENTION: parameter passed BYREF will return info
) AS LONG
After that you will be able to call thinBasic_ChangeVariableStringDirect or thinBasic_ChangeVariableNumberDirect to change value inside the variable passing back the above parameters and the value you need to assign to the variable:
'----------------------------------------------------------------------------
'thinBasic_ChangeVariableStringDirect
'----------------------------------------------------------------------------
' See also thinBasic_VariableParse
'
' Change a variable using direct variable pointer's data returned by
' thinBasic_VariableParse. This will ensure to work also with arrays
'----------------------------------------------------------------------------
DECLARE FUNCTION thinBasic_ChangeVariableStringDirect _
LIB "thinCore.DLL" _
ALIAS "thinBasic_ChangeVariableStringDirect" _
( _
BYVAL VariablePtr AS LONG , _
BYVAL VariableAbsPos AS LONG , _
BYVAL lValString AS STRING _
) AS LONG
'----------------------------------------------------------------------------
'thinBasic_ChangeVariableNumberDirect
'----------------------------------------------------------------------------
' See also thinBasic_VariableParse
'
' Change a variable using direct variable pointer's data returned by
' thinBasic_VariableParse. This will ensure to work also with arrays
'----------------------------------------------------------------------------
DECLARE FUNCTION thinBasic_ChangeVariableNumberDirect _
LIB "thinCore.DLL" _
ALIAS "thinBasic_ChangeVariableNumberDirect" _
( _
BYVAL VariablePtr AS LONG , _
BYVAL VariableAbsPos AS LONG , _
BYVAL lValNumber AS EXT _
) AS LONG
But if you are in hurry, the only possible way to pass a BYREF value in IBASIC is to get its data address (using VARPTR in the script) and change data directly using pointers. It should be possible to do it in IBasic but I do not know how. In PowerBasic you just need to define a variable pointer and than use it.
I will talk with Roberto about this. He did the IBasic interface.
Ciao
Eros
Michael Hartlef
06-10-2007, 21:22
Thanks for the info Eros.
Michael Hartlef
06-10-2007, 21:25
are you saying that you want to directly access the memory locations of posx,posy,posz because I dont see any way that thinbasic can pass pointers for IBASIC.
I dont use IB so this is a quick observation so I could be wrong.
Yes Abraxas, and like Eros said, with the PowerBasic SDK it is possible. The TBGL module does it quite often. But it isn't a big problem for me that this is not possible with IBasic Pro.
ErosOlmi
06-10-2007, 21:31
Mike,
in any case we will improve IBasic interface. If you are using IBasic for a new module it is worth for us to support you.
Just give us some days due to high workload at "real life work" ;)
Ciao
Eros
Michael Hartlef
07-10-2007, 00:14
Eros, it isn't really needed. Work on it only if you have nothing else better to do.
ErosOlmi
07-10-2007, 00:37
No problem Mike.
We just need to add a new function interface called something like "thinBasic_ChangeVariableDWORDDirect" because "thinBasic_ChangeVariableNumberDirect" accepts EXTENTED data type while IBasic has no EXT number support.
While "thinBasic_VariableParse" function interface can be used also for IBasic because it just needs two LONGs passed BYREF
Ciao
Eros
Michael Hartlef
07-10-2007, 10:26
Another thing why I might not need is that I bumped into a serious speed problem with my module. So I'm not sure if IBP is the problem or the algorythm itself. Could be that I will port it to a different language.