Passing arguments from revolution to c++ external

Are you developing an External using the LiveCode Externals SDK?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
n.allan
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 153
Joined: Mon Mar 12, 2007 12:06 pm

Passing arguments from revolution to c++ external

Post by n.allan » Tue Oct 30, 2007 12:12 pm

I love the external newsletters and am dabbling with using externals in order to access more popular c++ SDK's

I know very basic c++ so my main questions are:

Can you only pass an array of c-strings to your external or can you pass integers and booleans? Do you have to pass them as chars then convert them in your external? Indeed does it have to be an array? or can you pass a string of comma seperated variables for you external function to act on?

Forgive me if I'm a bit vague on the subject, but my understanding is quite limited on c++

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Post by trevordevore » Tue Oct 30, 2007 7:36 pm

The parameters you pass from Revolution to the function/command defined in the external will always be passed as an array of strings. At that point you can coerce the values as needed.
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

n.allan
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 153
Joined: Mon Mar 12, 2007 12:06 pm

Post by n.allan » Wed Oct 31, 2007 11:21 am

So I need to typecast them on the c++ side.

I realise this is not a c++ forum so I'll make this my last. I have one other problem. I can only seem to access the first element of the passed array in c++, I'm not even sure if i'm passing a multi element array.

from runrev:

answer externalfunction("Hello World") --is this an array of chars?

on the c++ external:

void externalfunction(char *p_arguments[]...yada yada..)

strdup(*p_arguments[]) returns "Hello World" to runrev answer box

strdup(*p_arguments[1]) throws an error in visual studio express about memory access

How can I pass a multi dimensional array to my external from runrev?

If i've totally missed the point let me know I'll just habe to figure something out.

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Post by trevordevore » Wed Oct 31, 2007 2:45 pm

n.allan wrote:So I need to typecast them on the c++ side.
Yes.
I can only seem to access the first element of the passed array in c++, I'm not even sure if i'm passing a multi element array.

from runrev:

answer externalfunction("Hello World") --is this an array of chars?
Actually this is an array of C-strings which I think is where you are confusing things. Given the above call *p_arguments[0] will contain the string "Hello World". *p_arguments[1] is not defined. If you were to call the following handler:

answer externalfunction("Hello World", "Hello again")

then *p_arguments[1] would be "Hello again".
on the c++ external:

void externalfunction(char *p_arguments[]...yada yada..)

strdup(*p_arguments[]) returns "Hello World" to runrev answer box

strdup(*p_arguments[1]) throws an error in visual studio express about memory access
Note that you can use p_argument_count to determine the length of the p_arguments array. In your example p_argument_count would be 1. Given this, you would know that calling p_arguments[1] would result in sadness.
How can I pass a multi dimensional array to my external from runrev?
Passing an array from Revolution to the external is a little different. You can't pass the actual array. What you have to do is pass the name of the variable to the external. Look at the second external article for examples of this:

http://www.runrev.com/newsletter/novemb ... etter3.php

There is a section "Delving into arrays" and Revolution arrays are passed back and forth to the external so there should be some good example code in there.
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

n.allan
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 153
Joined: Mon Mar 12, 2007 12:06 pm

Post by n.allan » Wed Oct 31, 2007 3:05 pm

Thanks for your replies, That explains a lot. I shall go forth and experiment.

Post Reply

Return to “Building Externals”