rulfzid wrote:
Instead of programming in what you call a "mix" of OOP and AHK OOP, you could write some basic class specs in a markup language (ini, json, xml).
I like, I like. That would DEFINITELY make creating a class much easier. This would be a great improvement over the current design.
Just to clarify, user-defined values are not part of the class' ahk file. Rather, they are extensions to a class as specified by the user. These values / functions can differ between projects, and provide a way to associate extra values with a class object. However, I could probably add support for user-defined values / functions. It would be in a separate file from the built-in values / functions. I would also work out a "standard" structure for user-defined values, because right now specfying user-defined values isn't as structured as I would like.
Also, your idea could be extended to allow specifing constants - via the constants method. I'll figure something out that's "neat". Read-only constants would be created by specifing "ReadOnly" after the variable (see example below). To allow specifying multi-line text values, the format will mimic the
Class_setConstant function which will be released with the new updates. By specifing "Code" after the variable name, the specified text will be copied as code. This allows initializing a value based on some code. The value will only be initialized once - which I forgot to do in the Browser Class...oops - I'm going to fix this, thanks.
I'll also add a "static" option to specify a function as static. If not specified, the function is presumed to be non-static (which most will be).
For parameters, I don't think xml is required (see below example). Param1, in all cases, is the first paramater. For non-static, you don't specify the ClassObject - it is added automatically. Param1 would be the first parameter after the Class object on which to act.
Code:
[Class]
Name=Rectangle
Wrapper=1
Cloneable=1
BuiltInValueCount=2
BuiltInMethodCount=1
UserDefinedValueCount=0
UserDefinedMethodCount=0
;specify to have the constants function included, but left empty
;if any constants are defined below, this setting is ignored
;omitting this setting (with no constants defined below) would have the constants function omitted from the resulting source.
;Constants = 0(/false/no)
;optional section - if omitted the constant function will be omitted.
[Constants]
`value1 = 5.0
;a read only constant
`value2 ReadOnly = 7
;a constant copied as code (ReadOnly)
;will use ":=", not an "="
`FireFox ReadOnly Code = Browser_new("Firefox", "(?:<<<URL>>> - )?Mozilla Firefox", "^l")
[BuiltInValue1]
Name=Width
Type=UShort
[BuiltInValue2]
Name=Height
Type=UShort
[BuiltInMethod1]
Name=Area
;static = true/false
;Param1 = arg1
;Param2 = arg2
Source=Rectangle_source.ahk
On a side note, would it make sense to to allow specifing the source code's source? For example, you would have the ini, and specify an ahk file that contains the functions source. Then, the converter would "merge" the ini with the source. This would be, for example, mimicing C++ .h file. The ".h" would be the specified source code file. You could store all the functions in one big ahk "source" file (e.g. MyClass_source.ahk), or split the source in how ever many files you want - even one for each. Since the files are AHK files, you can use the syntax highlighting from your text editor (if applicable).
Additionally, the "tradional OOP -> AHK OOP" converter could be applied to the different functions (via the specified source file) on merge (this could be disabled). For me, at least, I miss the OOP syntax, and this would allow writing the source in the format that suits the writter (whether tradional OOP, AHK OOP, or a mix).
Then, on merge, it is all grouped together in the resulting MyClass.ahk file. If you keep the source in a separate file(s) (ex. MyClass_source.ahk), then the original source remains in whatever form you specify. To avoid having to tell the converter each time how you want it converted, after converting something once, it would store the converted version (in a comment) above the actual version (as seen in the ahk file). It would only be a "linking message" - recognized by the converter - ex. ";OOP Converter 1". This way, it doesn't become a distraction if the result is long or complicated. Addionally, using this method means that even as the code gets modified, the link remains. Deleting the link will void the "cached" conversion.
The "cache" file would be the mirror of the original source, but converted. It would contain the same "linking message" as the original. This will point the original to it's cached conversion (if it exists). If the filename were SomeCode.ahk, the cache file would be SomeCode_cache.ahk. It's just the start of an idea, so the final result will probably differ, at least in part, from what I just said.
rulfzid wrote:
Also, a quick question: is there an easy way to do inheritance with your Class library?
This is in the works. I have interfaces done (haven't uploaded it yet - been distracted). Interfaces are "skeletons" of a Class - as seen in Java.
Still writing examples and working on the docs for it. Was waiting til I got that done. I'll work on that and post it soon.
True inheritence will be built from this same idea. There may be some limits to inheritence, due to AHK not being an OOP language, but they shouldn't be of much concern. I think I can support multiple inheritence, but no promises.
Thanks for this awesome feedback - I'll start on it.
_________________
As always, if you have any further questions, don't hesitate to ask.
Add OOP to your scripts via the
Class Library. Check out
my scripts.