Support > General Discussions
Embedding into application
Zulfi.Ali:
I have looked at the developer docs esp for embedding ScriptBasic.... but no reference to setting array elements...
If you have any suggestion then do let me know as I will try it out myself...
Support:
Maybe Armando or Peter can chime in and shed some light on accessing arrays.
Verhas:
To embed ScriptBasic into an application the interface developed in the source file scriba.c should be used. This is fine so far, as I can see that you use the functions defined in that file. You only struggle with the fact that this interface does not give access to you to global variables that contain arrays. This is by design and I will try to e4xplain it, and I will try to convince you to try to find some other way to solve your problem, rather than wanting directly manipulate array variables.
A ScriptBasic program has global variables and functions and functions also have local variables. The global variables are stored in a table and arrays can build up quite complex structures. These structures
may even lead to memory leak in the sense that some unused memory is not released or reused by ScriptBasic until it finishes the execution. Because the memory structure of ScriptBasis is complex I decided
not to provide interface to access variables only to functions. Later on I bended due to popular pressure from users of ScriptBasic and now it is possible to set/get global variables before invoking functions. But still you can not set a variable to hold an array, and calling
--- Code: ---v = scriba_LookupVariableByName(pProgram, "main::a[0]")
--- End code ---
is a total non-sense. This would try to look up a variable that has the name
--- Code: ---main::a[0]
--- End code ---
which is indeed not a valid variable name.
My suggestion is that you set one global variable to hold a string. String in ScriptBasic is an arbitrary length binary value, therefore it can hold any value. After that your BASIC code should split and convert this value to an array. Something like:
--- Code: ---v = scriba_LookupVariableByName(pProgram, "main::a")
scriba_SetVariable(pProgram, v, SBT_STRING, 0, 0, binaryStringData , lengthOfString)
--- End code ---
note that the variable binaryStringData need not be zero terminated, and may contain zero characters. After this the BASIC program could
--- Code: ---
i = 0
while length(a) > 0
unpack a format "I4" to q[i]
i=i+1
a = mid$(a,4)
wend
--- End code ---
I did not check this code, may be erroneous, but the general idea should be fine.
Support:
I ran into the same array limitation using the MT module. (can't store arrays as session variables) I solved my problem using the T extension module functions ArrayToString() and StringToArray().
Zulfi.Ali:
Hi,
Thanks for your reply... now I am trying to pass the array as a string... my problem is how do I create the string from the array in my C program to pass to the variable? The T module is designed to be used from inside the BASIC script so I cannot use the ArrayToString() function...
More help needed..
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version