in B4R variables can be byte, int, uint, Long, Ulong double, String and ArrayByte. ( but also ArrayInt, ArrayUint, ArrayLong, ArrayUlong, ArrayDouble)
between B4R and inline C we can use only one variable "Object" and an Object can support Long, Ulong, Double and a pointer. Long, Ulong, double and Pointer are inside Object.
Pointer is used to Const char* from B4RString or char* from Arraybyte
Pointer can be a pointer to an array of Objects if you go to inline C with an array of Object
conversion to Object is done automatically .
in inline C, you have to recover your variable :
first you can check o-> type to know what are parameters in this Object and after you can recover variables sent.
an example below where in your inline C you can recover Long, Ulong, Double, String or arraybyte :
#if c
void myobject(B4R::Object* o) {
byte Type = o->type;
Serial.print("Object1 type : ");Serial.println(Type);
Long Long1; ULong ULong1; Double Double1; const char* cchar1; char* char1; B4R::Array* ar1;B4R::Array* ar2; B4R::Object** arrayOfPointers;
//case RunNative("myobject",-25)
if (Type == 5) { //Long
Long1 = o->toULong();
Serial.print("content : ");Serial.println(Long1); }
//case RunNative("myobject",25)
if (Type == 6) { //ULong
ULong1 = o->toULong();
Serial.print("content : ");Serial.println(ULong1); }
//case RunNative("myobject",25.32)
if (Type == 7) { //Double
Double1 = o->toDouble();
Serial.print("content : ");Serial.println(Double1); }
//case RunNative("myobject","inline C tests")
if (Type == 101) { //case string in const char*
cchar1 = (const char *)B4R::Object::toPointer(o);
Serial.print("content : ");Serial.println(cchar1); }
//case RunNative("myobject","inline C tests".getbytes)
if (Type == 100) { //case array direct
ar1 = (B4R::Array*)B4R::Object::toPointer(o);
char1 = (char*)ar1->data;
Serial.print("content : ");Serial.println(char1); }
};
#End If
it is my understanding of Object used from B4R to inline C.
i hope i don't make mistake...
if you have several variables array, String, byte, etc... to send to inline C, you can create an array of Objects in B4R and send it to inline C
//example with :
Dim xx as Double == 25.678
Dim tsts() As Object = Array(xx,"azerty",1000,"next".getbytes,105.00,"last","10")
#if c
void myobject(B4R::Object* o) {
byte Type = o->type;
Serial.print("Object1 type : ");Serial.println(Type);
Long Long1; ULong ULong1; Double Double1; const char* cchar1; char* char1; B4R::Array* ar1;B4R::Array* ar2; B4R::Object** arrayOfPointers;
// first you have to recover Array of Objects
if (Type == 100) { //case array of Objects
ar1 = (B4R::Array*)B4R::Object::toPointer(o);
Serial.print("Array length : ");Serial.println(ar1->length);
arrayOfPointers = (B4R::Object**) ar1->data;
B4R::Object* c[ar1->length];int i;
for(i = 0; i <ar1->length; i++)
{
c= arrayOfPointers;
Serial.print("Object c[");Serial.print(i);Serial.print("] type : ");Serial.println(c->type);
switch (c->type) { //test Object type
case 5 : // Long
Serial.print("value Long: "); Serial.println(c->toLong());
break;
case 6 : // ULong
Serial.print("value ULong: "); Serial.println(c->toULong());
break;
case 7 : // Double
Serial.print("value Double: "); Serial.println(c->toDouble());
break;
case 100 : //Pointer to char*
ar2 = (B4R::Array*)B4R::Object::toPointer(c);
char1 = (char*)ar2->data;
Serial.print("content : ");Serial.println(char1);
break;
case 101 : //pointer to const char*
char2 = (const char *)B4R::Object::toPointer(c);
Serial.print("content : ");Serial.println(char2); } }
};
#End If