[Not necessary]Support load method call without #include

Propose new features and changes
User avatar
RobertL
Posts: 540
Joined: 18 Jan 2014, 01:14
Location: China

[Not necessary]Support load method call without #include

20 Aug 2014, 10:11

Functions wrote:Libraries of Functions: Standard Library and User Library
A script may call a function in an external file without having to use #Include
Load functions and method from an external file in Libraries.

Because, I actually use class, instead of function. Such as MyClass[a](b)(a Meta-Functions).
And don't want to contain #Include<MyClass> in code.
Last edited by RobertL on 27 Aug 2014, 21:05, edited 1 time in total.
我为人人,人人为己?
lexikos
Posts: 7309
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Support load method call without #include

20 Aug 2014, 16:34

See Q: Class libraries?

You just need to call a function from that script anywhere in your main script. For instance,

Code: Select all

MyClass(prms*) {  ; Call this to create a MyClass and auto-include the script.
    return new MyClass(prms*)
}
User avatar
RobertL
Posts: 540
Joined: 18 Jan 2014, 01:14
Location: China

Re: Support load method call without #include

20 Aug 2014, 20:08

There is no function in that script(they are all method in class).
And I think it's more efficient to use MyClass[a](b) directly in any where at any time, without thought to put #Include<MyClass>, or first call a function from that script.
Because there will be many Libraries like this through the target script, so it's easy to forget whether already had a call when insert a new MyClass[a](b) instance.
Q: Class libraries? wrote:Class names are just global variable names
I think variable and function (also label) are different mechanisms. There may be duplicate name, so can't use auto-include.

The method is like table(object)+function(not just function in namespace), similar like closure/contain upvalue.
我为人人,人人为己?
lexikos
Posts: 7309
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Support load method call without #include

20 Aug 2014, 20:48

RobertL wrote:There is no function in that script
So add one!
And I think it's more efficient to use MyClass[a](b) directly in any where at any time, without thought to put #Include<MyClass>, or first call a function from that script.
You don't need to think about it. Just make the usage of your class like this:

Code: Select all

myObject := MyClass()
not:

Code: Select all

myObject := new MyClass()
after defining the MyClass() function as in my previous post. Is this not more efficient than using #Include <MyClass> in each script which uses the class? On the other hand, it may be more efficient to always #Include each library - although it requires more typing, it makes the script's requirements very clear, and doing it by habit means you won't need to debug your script when it fails due to not auto-including a file.

Of course, you can't do exactly that if you're just calling static methods of MyClass and not instantiating it. But if you're just calling static methods, there isn't really any benefit of using MyClass.Func() over MyClass_Func() (and there are performance penalties).

You don't have to call MyClass() before referring to MyClass. You just need the script to contain at least one call to that function. It doesn't even need to actually be executed.
I think variable and function (also label) are different mechanisms.
Yes.
There may be duplicate name,
That's irrelevant. The reason new MyClass or MyClass.Foo() can't auto-include is that MyClass could be something defined by the script at runtime - the interpreter has to assume it already has everything it needs and does not need to include some other file.
User avatar
RobertL
Posts: 540
Joined: 18 Jan 2014, 01:14
Location: China

Re:

20 Aug 2014, 21:51

I don't want to use myObject := MyClass() every time. I would be redundance when large script.
But I think MyClass()[a](b) would be better. MyClass[a](b) best.

Code: Select all

MyClass(){
	return MyClass	;this didn't use instance of class.
}
Although it's some case/extremes not really exist for me.
But prepare when thought.

After create Lib, the efficient means easy to use/code.
it may be more efficient to always #Include each library
Good idea.(Use one main #include is enough)
But... :crazy:
there isn't really any benefit of using..
No, there is some!

Code: Select all

class Mouse extends Mouse.B{
	class B{
		__Get(k){
			MouseGetPos x,y
			if k="x"
				return x
		}
	}
}MsgBox % Mouse.x ;Easy to use ~
ExitApp
Like built-in variable, user can define their own L.xx, L.yy.
at least one call to that function
This is the problem!
I want to use the method, but I don't konw whether already contain it, so I would have to search or re-contain again.

Eh..
MyClass could be something defined by the script at runtime..
I see, function is static, variable(class) is dynamic.
It seems no way to solve it.
我为人人,人人为己?
lexikos
Posts: 7309
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Re:

20 Aug 2014, 22:10

RobertL wrote:I don't want to use myObject := MyClass() every time. I would be redundance when large script.
I think you're still missing the point. That would be used in place of myObject := new MyClass(). If you aren't using new MyClass, then the suggestion isn't applicable.
No, there is some!
Read my post before replying to it. You aren't calling static methods.
I wrote:But if you're just calling static methods, there isn't really any benefit of using MyClass.Func() over MyClass_Func() (and there are performance penalties).
However, thanks for the example.
RobertL wrote:so I would have to search or re-contain again.
I don't know what you mean by "re-contain". What's the problem with just inserting another call to the function? It would show very clearly that this section of code uses that library. If it doesn't actually get called, there is no speed cost. If it gets called but does nothing, the cost is very small.
User avatar
RobertL
Posts: 540
Joined: 18 Jan 2014, 01:14
Location: China

Re: Support load method call without #include

20 Aug 2014, 23:07

Sorry, I didn't notice static methods. I didn't distinguish between static, non-static, nor dynamic. (Discussed in this post at <Method In OnMessage >)

As the example show, class Mouse is the Lib, Mouse.x is the usage.

Code: Select all

Mouse()
Mouse.x ;right.
;But...long code after
Mouse() ;I forget there is already one/many, so it's redundance.
Mouse.x
I don't want to contain anything else (#include/call) besides them.
Also I don't need to include them explicitly or clear. Just use Mouse.x is enough like they are built-in.

That's my target. But I realize this make excessive demands.
Maybe use one #include to include all of them is easier.
我为人人,人人为己?
lexikos
Posts: 7309
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Support load method call without #include

21 Aug 2014, 03:19

RobertL wrote:Sorry, I didn't notice static methods. I didn't distinguish between static, non-static, nor dynamic.
You weren't calling a method of any type. Mouse.x() is a method call. Mouse.x is not.
User avatar
RobertL
Posts: 540
Joined: 18 Jan 2014, 01:14
Location: China

Re: Support load method call without #include

21 Aug 2014, 03:52

I thought Mouse.x acutally call meta-function?
Forget it. I will use #include/call.
我为人人,人人为己?

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 4 guests