Sign in to follow this  
pbody2012

How to pass array<string>& to a function?

Recommended Posts

pbody2012    115

Just as the title says, how do i pass array<string>& to a function?

 

I have this function defined in anglescript and I have other script functions calling it.  However, it is failing to compile with this message: unit-spec.as (5,25) : ERR : Expeted ">" or ","

 

bool stringInList( array<string>& arg, string s )
{
	for( uint n = 0; n < arg.length(); n++ )
	{
		if( arg[n] == s )
			return true;
	}
	return false;
} 

 

 

Share this post


Link to post
Share on other sites
WitchLord    4677

This is the correct way to declare a function that takes an array reference as input and output. It shouldn't be a problem compiling this. It's possible that you've stumbled on a bug in AngelScript, however I'm not able to recreate any problem with just this script sample.

 

What version of AngelScript are you using? 

 

Are you using any non-default options in your application, e.g. asEP_ALLOW_UNSAFE_REFERENCES?

 

Are you using namespaces?

Share this post


Link to post
Share on other sites
pbody2012    115

I'm using version 2.26

I am not using any non default options, I have not touched these at all.

I am using a namespace but it is for another piece of code.

This code is in a separate file and it is being included in another file.

Share this post


Link to post
Share on other sites
WitchLord    4677

Though you don't want to use the repository version yet, would it be possible for you to just give it a try to see if it fixes the problem you're having? There hasn't been any changes to the interface so it should just be a matter of recompiling your app with the new header (to get the right ANGELSCRIPT_VERSION).

Share this post


Link to post
Share on other sites
pbody2012    115

Ok I found out that I forget to register the array types, so I did that.  The function is compiling, however I cant it.

 

I have the following code that I call the function from:

 

array<string> gEngineRPMUnits = { "stall-rpm","start-rpm","idle-rpm","redline-rpm","max-rpm" };

string VerifyEngineUnitSpec( string attribute, string unitSpec )
{
	// local
	// string result;
	
	// check for rpm
	if( stringInList(gEngineRPMUnits,attribute) )
	{
		// unit has to be rpm, rps, rad/s
		if( unitSpec!="revolution" )
			return "error";
		else
			return unitSpec;
	}
        return "";
}

 

Is this valid?

Share this post


Link to post
Share on other sites
WitchLord    4677

Yes. this is valid code. 

 

Perhaps you could share what problem you're facing? Are you getting compiler errors? Or is the code not behaving as you expect? 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this