B4R Question [SOLVED] B4R Array

Daestrum

Expert
Licensed User
Longtime User
Does the Array object contain an indication of the data type of the elements?
 

Cableguy

Expert
Licensed User
Longtime User
Sorry, I don't quite understand the question...
When you declare an array you also declare what type of objects it will contain...
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Sorry, I don't quite understand the question...
When you declare an array you also declare what type of objects it will contain
When you pass the Array to c code I was hoping it stored the type so you could use a common routine to 'unpack' the Array.
 
Upvote 0

thetahsk

Active Member
Licensed User
Longtime User
Does the Array object contain an indication of the data type of the elements?
A short code snippet to determine the runtime type. See the defines in rCore.h,
#define BR_BYTE 1
#define BR_CHAR 2
#define BR_INT 3
.....

Pass the first element of your array to the Runtime_Check function.
B4X:
Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    Dim f_array() As Float = Array As Float(10.10,20.20)
    Dim b_array() As Byte = Array As Byte(11,22)
    RunNative("Runtime_check",f_array(0))
    RunNative("Runtime_check",b_array(0))
    RunNative("Runtime_check",f_array)   'not working return 100
    RunNative("Runtime_check",b_array)   'not working return 100
End Sub

#if C
void Runtime_check(B4R::Object* o) {
   // see e.g. #define BR_DOUBLE 7 in rCore.h
   if (o->type==7) ::Serial.println("Double type");
   if (o->type==5) ::Serial.println("Byte type");
   ::Serial.println(o->type);
   ::Serial.println("------------");
}
#End if
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
I have it working now - I wrapped the array I want in another array that holds the data in the format I want eg int or long or byte.
And now have a routine that can read any array regardless of data type.

Will post the code once I have optimised it fully.
 
Upvote 0
Top