Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Extra libraries, Code snippets, applications etc. » U++ Esc Interpreter, Esc Macros and templates » How to declare a global var without id in *.upt?
How to declare a global var without id in *.upt? [message #3068] Fri, 05 May 2006 22:09 Go to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
How to declare global vars without id in *.upt?

I'm running out of space in the templates dialogue window... Smile

But, anyway, is it possible to declare extra global vars without using id's or, maybe in the worst case, to hide those fields?

[Updated on: Fri, 05 May 2006 22:09]

Report message to a moderator

Re: How to declare a global var without id in *.upt? [message #3069 is a reply to message #3068] Fri, 05 May 2006 22:39 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
fudadmin wrote on Fri, 05 May 2006 16:09

How to declare global vars without id in *.upt?

I'm running out of space in the templates dialogue window... Smile

But, anyway, is it possible to declare extra global vars without using id's or, maybe in the worst case, to hide those fields?



Eh, now I am not quite sure what is your plan. What is "variable without id" ?

(Other than that, global variables are simply prefixed with ':').

Mirek
Re: How to declare a global var without id in *.upt? [message #3070 is a reply to message #3069] Fri, 05 May 2006 23:29 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
My plan is simple: to generate some classes and methods depending on some entered numbers.
I've quite succeeded but I want to optimize more...

this code below generates: "func0 func1 func2" etc.

id "How many funcs" funcCount="5";

class blabla : staticRectangle {
public: 
<:{ x = ""; lim1=to_number(:funcCount); for(i = 0; i < lim1; i++) x<<"func"<<to_string(i)<<" "; return x; }:>
}


I want x to use like :funcCount somewhere below for other classes.
Re: How to declare a global var without id in *.upt? [message #3071 is a reply to message #3070] Fri, 05 May 2006 23:31 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
O maybe to have Esc functions? And send params?
Re: How to declare a global var without id in *.upt? [message #3084 is a reply to message #3071] Sat, 06 May 2006 07:10 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
fudadmin wrote on Fri, 05 May 2006 17:31

O maybe to have Esc functions? And send params?


Still not sure about that global bar (but global vars really just :id).

To define function, use <:!. See EscRun.cpp / Expand - that is the routine used to expant those .upt.

(BTW, there is quite a real power when using this Expand together with Qtf and Sql and RichEdit to generate documents based on templates (written in Qtf/Esc combo) that can be edited to the final form;)

Mirek
Re: How to declare a global var without id in *.upt? [message #3088 is a reply to message #3084] Sat, 06 May 2006 12:37 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
luzr wrote on Sat, 06 May 2006 06:10



Still not sure about that global var (but global vars really just :id).

Mirek


I'm not against id's! Smile But I don't want a field displayed for each of them. Is there a possibility without changing Template.cpp?
Re: How to declare a global var without id in *.upt? [message #3090 is a reply to message #3088] Sat, 06 May 2006 14:49 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
fudadmin wrote on Sat, 06 May 2006 11:37

luzr wrote on Sat, 06 May 2006 06:10



Still not sure about that global var (but global vars really just :id).

Mirek


I'm not against id's! Smile But I don't want a field displayed for each of them. Is there a possibility without changing Template.cpp?


I think, I've tricked Esc and *.upt! Cool

<:!testf(){ return "testreturn"; }:> //declare a global function

<:testf():>   //this outputs "testreturn"

<:{ :testf=10; return;}:>  //make a global var from a function!!!

<:testf:>  //this outputs 10!!!


What can you say?
Re: How to declare a global var without id in *.upt? [message #3109 is a reply to message #3090] Sun, 07 May 2006 19:48 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
fudadmin wrote on Sat, 06 May 2006 08:49

fudadmin wrote on Sat, 06 May 2006 11:37

luzr wrote on Sat, 06 May 2006 06:10



Still not sure about that global var (but global vars really just :id).

Mirek


I'm not against id's! Smile But I don't want a field displayed for each of them. Is there a possibility without changing Template.cpp?


I think, I've tricked Esc and *.upt! Cool

<:!testf(){ return "testreturn"; }:> //declare a global function

<:testf():>   //this outputs "testreturn"

<:{ :testf=10; return;}:>  //make a global var from a function!!!

<:testf:>  //this outputs 10!!!


What can you say?



Well, you have not tricked Esc, this how it is designed. Lambda is value.

Maybe I am starting to get what is your confusion - you do not know how to "declare" global variable?

You do not need to declare variable in Esc, just to assign them.
Try:

<: :xxx = 10; :>

<: :xxx :>


Mirek
Re: How to declare a global var without id in *.upt? [message #3124 is a reply to message #3109] Sun, 07 May 2006 23:50 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
<: :xxx = 10; :>

<: :xxx :>

If that worked I wouldn't have asked... Sad
Are you sure this works with *.upt?
For me it says #ERROR: missing :>
Re: How to declare a global var without id in *.upt? [message #3125 is a reply to message #3124] Mon, 08 May 2006 01:38 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
fudadmin wrote on Sun, 07 May 2006 22:50

<: :xxx = 10; :>

<: :xxx :>

If that worked I wouldn't have asked... Sad
Are you sure this works with *.upt?
For me it says #ERROR: missing :>


Can be a bug? Because it works like this:
<: :xxx = 10 :>

<: :xxx :>

Edit:
But, in this case, if I assign a number or a string Esc outputs them. Maps and arrays are OK.

[Updated on: Mon, 08 May 2006 02:03]

Report message to a moderator

Re: How to declare a global var without id in *.upt? [message #3126 is a reply to message #3125] Mon, 08 May 2006 07:32 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
fudadmin wrote on Sun, 07 May 2006 19:38


Can be a bug? Because it works like this:



Yes, sorry. <: is for expression, <:{ is for block of statements, that ';' makes it an expression.

Quote:


Edit:
But, in this case, if I assign a number or a string Esc outputs them. Maps and arrays are OK.


What is wrong then?

BTW, strings are arrays, there is no difference. Also, maps are structures,

a.b

is same as

a["b"]

Mirek
Re: How to declare a global var without id in *.upt? [message #3128 is a reply to message #3126] Mon, 08 May 2006 12:46 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
The problem is that if I assign to a global var a string or a number, their values are printed in the place of assignment. And that messes up *.h/*.cpp files...
Re: How to declare a global var without id in *.upt? [message #3130 is a reply to message #3128] Mon, 08 May 2006 13:46 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
fudadmin wrote on Mon, 08 May 2006 06:46

The problem is that if I assign to a global var a string or a number, their values are printed in the place of assignment. And that messes up *.h/*.cpp files...


Ah, of course, because if you do you <: :>, it is expression that gets evaluated and inserted. Use <:{ :global = ... ; }:> instead.

Mirek
Re: How to declare a global var without id in *.upt? [message #3131 is a reply to message #3130] Mon, 08 May 2006 14:15 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
luzr wrote on Mon, 08 May 2006 12:46

fudadmin wrote on Mon, 08 May 2006 06:46

The problem is that if I assign to a global var a string or a number, their values are printed in the place of assignment. And that messes up *.h/*.cpp files...


Ah, of course, because if you do you <: :>, it is expression that gets evaluated and inserted. Use <:{ :global = ... ; }:> instead.

Mirek



Thanks! That works!
I didn't manage to guess that when unsuccessfully tried this one (with spaces between <: and { ):
<: { :global = 10; } :>

Ech, those little things...

Anyway, Esc is PHP in Ultimate++! Very Happy

[Updated on: Mon, 08 May 2006 14:16]

Report message to a moderator

Re: How to declare a global var without id in *.upt? [message #3132 is a reply to message #3130] Mon, 08 May 2006 14:58 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
luzr wrote on Mon, 08 May 2006 12:46

fudadmin wrote on Mon, 08 May 2006 06:46

The problem is that if I assign to a global var a string or a number, their values are printed in the place of assignment. And that messes up *.h/*.cpp files...


Ah, of course, because if you do you <: :>, it is expression that gets evaluated and inserted. Use <:{ :global = ... ; }:> instead.

Mirek



Sad
No, in fact this doesn't work. Could you check if this works for you? For me it says "invalid expression"...
Re: How to declare a global var without id in *.upt? [message #3133 is a reply to message #3132] Mon, 08 May 2006 15:07 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
fudadmin wrote on Mon, 08 May 2006 08:58

luzr wrote on Mon, 08 May 2006 12:46

fudadmin wrote on Mon, 08 May 2006 06:46

The problem is that if I assign to a global var a string or a number, their values are printed in the place of assignment. And that messes up *.h/*.cpp files...


Ah, of course, because if you do you <: :>, it is expression that gets evaluated and inserted. Use <:{ :global = ... ; }:> instead.

Mirek



Sad
No, in fact this doesn't work. Could you check if this works for you? For me it says "invalid expression"...


Maybe it will require .... return ""; } :>.

If it does, Expand needs fixing.

Mirek
Re: How to declare a global var without id in *.upt? [message #3134 is a reply to message #3133] Mon, 08 May 2006 17:06 Go to previous message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
Yes, your guess was precise... It works with return ""; ...
Previous Topic: Esc: how to convert from string to number (or integer)?
Next Topic: Esc: how to use recursion?
Goto Forum:
  


Current Time: Tue Apr 16 15:40:30 CEST 2024

Total time taken to generate the page: 0.01868 seconds