View Full Version : Global Variables
Hi all. This is my first post. I just discovered this site (today !!) and I immediately started playing with modules. I was impressed about how easily one can have a module up and running.
I onlty trid with the demo modules so far and here is my question.
Is it possible to define a variable that can be shared between modules and the thinbasic environment ? Think to something like equates but like a variable.
what I mean is a scenario like the following:
1) ModuleA define some new commands and some variables, let's say a variable called myvar of whatever type (let's say a string).
2) Now myvar van be used in tb scripts being assigned a value or used as parameter in function calls or return value.
3) some functions in moduleA (or another one ) needs to get the value of myvar. The module could also change the value of myvar.
Lua and Python already can do this but it's not so easy. What I'm asking if there is some trick to access the TB symbol table from inside a module.
There are other questions I have but, being a TB newbie, I hope to find the answers without bothering all the guys around here...
Cheers
Sandro
ErosOlmi
16-09-2008, 23:34
Ciao Sandro and welcome to thinBasic community.
thinBasic SDK for C/C++ is a very limited subset of the whole thinBasic SDK capabilities. The reason why is because so far there was not much interest in developing thinBasic modules using C/C++ languages.
But we can make some improvements on this ;)
To answer to your question: yes, there are many different ways to add variables on the fly at the module level exactly like you do for equates. The problem is that such an interface function is not present for C/C++ SDK
Let me talk with Roberto (in charge of SDK for C/C++ development) and we will add for the next version.
Ciao
Eros
ErosOlmi
16-09-2008, 23:42
Question: what C compiler are you using?
Hi Eros and thanks for your quick reply. I'm actually using Microsoft Visual C 6.0.
Some words about me:
I work for a company based in Bologna that sells software for numerical control. My primary job is techinical assistance to customers, but I also write postprocessors to let our software output code for mills and other CNC working centers and traslators to and from the most widely formats used in CAD CAM industry (mainly IGES and STEP)
I'm quite familiar with Visual C and Visual Basic 6.0 (.NET is too complicated for the little utilities I write).
I'm looking for a developement environment to write some programs to be used as code generators for computerized numerical control machines.
I found Thinbasic a potential ideal tool that mix the power of an interpreter with the ease of extensibility.
Ciao
Sandro
ErosOlmi
17-09-2008, 11:15
Sandro,
thanks for letting us know about your job details so we can get more info to achieve what you need.
As I posted, what you need is something thinBasic already does in other modules. Problem is that we give priority to PowerBasic and FreeBasic SDK so for those 2 languages there are a lot of interface function (more than 30) while for C there are just few (less than 10).
The reason why we keep Basic and C interfaces separated is the type of dynamic strings and numeric types we use. We normally use OLE strings (BSTR in C) while we use EXTENDED numeric variables (10 bytes). Those 2 types are not the most used in C applications.
Anyhow, thinBasic exposes the following interfaces:
'----------------------------------------------------------------------------
'thinBasic_AddVariable
'----------------------------------------------------------------------------
' Add a new variable to current stack level
'----------------------------------------------------------------------------
DECLARE FUNCTION thinBasic_AddVariable _
LIB "thinCore.DLL" _
ALIAS "thinBasic_AddVariable" _
( _
BYVAL vName AS STRING, _
BYVAL lValString AS STRING, _
BYVAL lValNumber AS EXT , _
BYVAL ForceType AS LONG _
) AS LONG
'----------------------------------------------------------------------------
'thinBasic_AddUdt
'----------------------------------------------------------------------------
' Add a new UDT structure
'----------------------------------------------------------------------------
Declare Function thinBasic_AddUdt _
LIB "thinCore.DLL" _
Alias "thinBasic_AddUdt" _
( _
ByVal sUDT_Code As String _
) As Long
'----------------------------------------------------------------------------
'thinBasic_ChangeVariableNumber
'----------------------------------------------------------------------------
' Change the value of a numeric variable giving its name a the new value
'----------------------------------------------------------------------------
DECLARE FUNCTION thinBasic_ChangeVariableNumber _
LIB "thinCore.DLL" _
ALIAS "thinBasic_ChangeVariableNumber" _
( _
BYVAL vName AS STRING, _
BYVAL lValNumber AS EXT _
) AS LONG
'----------------------------------------------------------------------------
'thinBasic_ChangeVariableString
'----------------------------------------------------------------------------
' Change the value of a string variable giving its name a the new value
'----------------------------------------------------------------------------
DECLARE FUNCTION thinBasic_ChangeVariableString _
LIB "thinCore.DLL" _
ALIAS "thinBasic_ChangeVariableString" _
( _
BYVAL vName AS STRING, _
BYVAL lValNumber AS STRING _
) AS LONG
In C you just have thinBasic_AddEquate interface function.
Also there are some other interfaces used to parse variables passed BYREF to modules functions. They are:
'----------------------------------------------------------------------------
'thinBasic_VariableParse
'----------------------------------------------------------------------------
' Instruct parser to get next token, check if variable, check if array and
' return 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
'----------------------------------------------------------------------------
'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
All those interface functions must be adapted to be used by modules developed in C and this required some time.
Of course you can alway develop module functions that expect a pointer to a variable. In this way you just parse a numeric value (the pointer to the variable).
Of course numeric types must match to the one you expect and maybe there can be some troubles with strings because thinBasic would pass the pointer to a BSTR.
So, imagine you have developed a module function named MyFUN expecting a DOUBLE passed BYREF, you can change it to expect a PTR to a DOUBLE variable.
In thinBasic script you would have something like:
DIM MyVar as DOUBLE
MyFUN(VARPTR(MyVar)
Instead for strings you can have the STRPTR (that returns a pointer to the first byte of the string) and VARPTR (that returns a pointer to the BSTR pointer)
Hope to have given some more info to work with while we will work to implement C DSK interfaces.
Ciao
Eros
PS: we are quite close to each other, we live and work close to Milano ;)
Thanks for your interest Eros. I spent some time looking at the Freebasic language. It seems a good tool (I only tdownloaded the doc for some browsing). I obviously like Basic languages and may be I could write my extension modules in FB rather than VC, so there is no need to improve the VC SDK expecially if it's not used by many guy around here.
I will absolutely try FB for my project. FB fr the modules and TB as main environment could be a good choice.
Sandro
RobertoBianchi
18-09-2008, 09:17
Sandro,
as you like, FreeBasic environment is a good choice.
In any case we will release shortly the updates for C/C++ SDK because it is actually too long time which did not update it.
Best regards,
Roberto
Hi Roberto. I'm happy that you are going to upgrade the C SDK. After the explanations of Eros about Freebasic I had a look at it. I'm quite impressed by the power of that language and I'm making some experiments with it. Obviously I usually fond myself more comfortable with C rather than Basic because , among the other things, I have a lot of code already written in C that I could easily port to TB as a module. I' will aboslutely wait for the upgrade guys.
Sandro