The Origin Forum
File Exchange
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Prob. with enum as a parameter in a Command Window
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

theuser

Germany
2 Posts

Posted - 07/07/2020 :  10:29:08 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin):
Operating System:

Origin Pro 2017 (64 bit) SR 2; b9.4.2.380

Windows 10.

Hello everyone!

I have a problem with passing an enum instance to the function via Command window, where as if I call a separate function and do the same everything works as expected.

Here is the minimum working example and the output:


#include <Origin.h>

typedef enum {first, second,third} Numbers_type;
void Somesomefunc123456(Numbers_type num)
{
		switch (num)
	{
		case first: out_str("is 1");
			break;
		case second: out_str("is 2");
			break;
		default: out_str("somenum");
		
	}
	
}

void anotherfunc()
{

Somesomefunc123456(first);
}


Call stack + output:

9> Somesomefunc123456(first)
Command Error!
10> anotherfunc()
is 1
12> Somesomefunc123456(1)
is 2
13> Somesomefunc123456(0)
is 1



Why the direct call via enum does not work? I need enum names like first, second and not integers for the actions, that the function will perform on the whole project (multiple folders, subfolders etc.), so simply passing numbers is not a solution I am looking for

Thank you in advance

cpyang

USA
1121 Posts

Posted - 07/07/2020 :  12:15:31 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Command Window is a LatTalk environment. OC enums are inside OC, not visible as LT variables.

We know of this limitation and we can improve it, but will need to be in a future version. I added JIRA ORG-22210 for this.

CP
Go to Top of Page

theuser

Germany
2 Posts

Posted - 07/08/2020 :  02:56:31 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by cpyang

Command Window is a LatTalk environment. OC enums are inside OC, not visible as LT variables.

We know of this limitation and we can improve it, but will need to be in a future version. I added JIRA ORG-22210 for this.

CP





Okay.

In case people will bump into this, I also tried #define and it did not work. Here is the possible workaround using "hashing" from string:


int Hash_testfunc54321(string command)
{
		if(command.CompareNoCase("Normalize")==0)return 0;
		else 
			{
				if(command.CompareNoCase("Rename")==0)return 1;
				else return 0xFFFF;
			}
	//Continue the Ladder for all the availiable commands
}


void maintestfunc12345(string command)
{
	switch(Hash_testfunc54321(command))
	{
	case 0: 
		out_str("it is Normalize");
		break;
	case 1: 
		out_str("it is Rename");
		break;
	//Continue for all the availiable commands
	default:
		out_str("something else");
		break;
	}
}


Labtalk call stack + output:

4> maintestfunc12345("Rename")
it is Rename
5> maintestfunc12345("Normalize")
it is Normalize
6> maintestfunc12345("Garbage")
something else


Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000