Custom static Functions

Post

Posted
Rating:
#1 (In Topic #1297)
Regular
sergioabreu is in the usergroup ‘Regular’
 If you go to Console and run RegExp.Match without running the program (in gambas "stand by") the function works because it is Static.

Does anyone know how to achieve this in a Custom Class/Module ? What is the recipe to have a working function that do not depend on running the program to test in console, like RegExp.match, RegExp.Replace etc ? Should be a component / package? How gambas name it?
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
I think I have answered this before.
Even though a module is static, it only exists (if that's the right word) when the project is running.

It is logical, if you think it through.

Afterthought. You seem to be desiring that the IDE be capable of running things outside its concept. The IDE is for coding, not testing. You may need to look at the Gambas "test" concept.

Online now: No Back to the top

Post

Posted
Rating:
#3
Regular
sergioabreu is in the usergroup ‘Regular’
 Are your answers a little "agressive" againt my questions or it is just a wrong impression ?

I just asked WHY REGEXP.FUNCTIONS can run in console without running a project and what class of thing is RegExp to work this way? Are some private "tools"  and not available to customization (adding new ones)?

More than a programmer I am a scientist.  Want to know things that ordinary programmers are not interested.
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
 No, you misunderstand me.

Imagine that I write some object oriented code in some other language in some theoretical IDE.
What I am trying to convey is "why cant I invoke an object method without running the program?"
And sorry, (no offense at all intended), because you cant!

Online now: No Back to the top

Post

Posted
Rating:
#5
Regular
sergioabreu is in the usergroup ‘Regular’
So, tell me WHY RegExp.Match and RegExp.Replace DOES function in console without running a project !

Because RegExp is a INSTANTIABLE class.

That's my initial question
Online now: No Back to the top

Post

Posted
Rating:
#6
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
 Sergio. as a scientist you must understand
The score and lyrics of "Stairway to Heaven" are not a song until it is performed by Led Zepplin or the Lord forbid by me on a pair of spoons. The code of a program is not an outcome until it is executed with the assistance of the local orchestra (or at least …)
Please forgive my intentional charisma.



Now, there was weird Autocorrect in that "Please" line.

ymmv

Online now: No Back to the top

Post

Posted
Rating:
#7
Regular
sergioabreu is in the usergroup ‘Regular’
You just fled from the question with a metaphore

RegExp.Match and RegExp.Replace work without an orchestra.

Maybe the answer is "PCRE is a package" (or a built-in class in gambas, like String).

If I write a new package, I would be able to have MyObject.function running as the same way as RegExp.Match without running a program.
Online now: No Back to the top

Post

Posted
Rating:
#8
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
 Yes. I think we are on the right track here. If I follow you. If you write a package i.e. a Gambas project that you then package and install in the proper way (as a component or library), then if your current project uses that component or library AND that package exhibits (returns) a call to a public method exposed by that package then you will be able to invoke the call via the IDE!
phew that took some grammar checks!
Keep going

Online now: No Back to the top

Post

Posted
Rating:
#9
Guru
BruceSteers is in the usergroup ‘Guru’
If you mean in the IDE console then it's probably an IDE feature.

nothing to do with static or non static in a class.
making a function or a property Static just means you access it without having to create an object and by accessing the class directly
eg..  Imagine a class called Tester.class

Code (gambas)

  1.  
  2. Static Public DefaultValue As Integer = 10
  3.  

Now you create a Tester object

Code (gambas)

  1. Dim hTest As Tester = New Tester
  2.  

now hTest.Value is an object value you can set but Tester.Value will error as Value is not static.
also trying to use hTest.DefaultValue will error but Tester.DefaultValue will work

Nothing to do with IDE features

if you need to test a function (you seem really keen to run functions separately without running code) just test it when running/debugging the application.

Code (gambas)

  1.  
  2. Public Sub Form_Open()
  3.  
  4. ' test my function then quit
  5. TestMyFunction()
  6.  
  7. ' usual code here
  8.  
  9.  
  10.  


What about gbx3 or gbs3 ?

Consider this in a terminal…
<HIGHLIGHT highlight="shell">
echo 'Use "gb.gui"
Dim iAnswer As Integer = Message.Question("How are you?", "Learning a new way","Stuck in my old ways")
If iAnswer = 1 Then
Print "awesome"
Else
Print "sort it out innit !"
Endif' | gbs3 -

</HIGHLIGHT>
awesome

So you see you can run bits of code simply using echo and | piping the text to gbs3 -

Also gbx3 -e like this..
<HIGHLIGHT highlight="shell">
gbx3 -e 'Format(Now,"ddd d mmm yyyy")'
</HIGHLIGHT>
Wed 24 Jul 2024

using -e evaluates an expression and prints it's result (same as using Eval in gambas) but it's not as versatile as gbs3 that can run text scripts.

Also maybe check out Brian's gsh  Gambas One - Gambas ONE
that's a terminal that you can directly use gambas code in (i do not know how, you'd have to read the docs)
Online now: No Back to the top

Post

Posted
Rating:
#10
Avatar
Enthusiast
GrayGhost is in the usergroup ‘Enthusiast’
would the Playground  be of any help to you :

https://gambas.one/playground/

<IMG src=""> </IMG>

Image

(Click to enlarge)

Online now: No Back to the top

Post

Posted
Rating:
#11
Regular
sergioabreu is in the usergroup ‘Regular’
No no no

I don't want to test or play anything. Just curious why Regexp.Replace worked in console without executing my project.

Many answers but did not focused on what I ASKED:

Regexp Static Functions  like Replace and Match will run in console without running a project probably because PCRE IS A PACKAGE and Gambas loads all packages when we start the project, leting these Static Functions of  theses Objects available on the console WITHOUT RUNNING the project.
  
Add PCRE and go to console F11 and run:

Code

  Regexp.replace("piano", "[a-i]", "e")

Thanks anyway.
Online now: No Back to the top
1 guest and 0 members have just viewed this.