Custom static Functions
Posted
#1
(In Topic #1297)
Regular

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?
Posted
Regular

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.
Posted
Regular

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.
Posted
Regular

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!
Posted
Regular

Because RegExp is a INSTANTIABLE class.
That's my initial question
Posted
Regular

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
Posted
Regular

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.
Posted
Regular

phew that took some grammar checks!
Keep going
Posted
Guru

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
Now you create a Tester object
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.
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)
Posted
Enthusiast

https://gambas.one/playground/
<IMG src="">
Posted
Regular

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.
1 guest and 0 members have just viewed this.



