Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Miscellaneous libraries


  • Please log in to reply
30 replies to this topic
adrianh
  • Members
  • 616 posts
  • Last active: Apr 07 2016 03:35 PM
  • Joined: 28 Oct 2012
I've been doing a few things and I thought I'd start sharing some of the libraries I've been making. They can all be accessed from here or can be accessed individually. However, some libraries depend on others.

Each file has documentation in the header as well as before each particular function.

I would also ask anyone using these libraries to add credit to me (as I would expect anyone using anyone else's library).

Object - Functions dealing with objects
  • object_elementList() - lists all members in an object.
  • object_getBase() - gets the base object without having to worry about accessing __Class member which can cause problems.
Depends on: Hex, ClassCheck

Modified Nov 22, 2012
  • Object_elementList() now handles self referenced and recursive referenced objects as well as nested classes.
  • Added OBJECT_SHOW constants and changed viewRealStructure parameter to an options bitfield. This shouldn't break existing code as long as only 0, 1, true or false were used as a passed value to viewRealStructure parameter.
  • Added ability to show regular strings and numbers. I.e.:
x := 5
object_elementList(x, "x") ; returns <x> = 5

Modified Nov 26, 2012
  • Gave object_elementList() more functionality.
  • Object_getBase() now checks to see if object passed is a Func object, if it is, return an empty string. Before it would infinitely recurse when trying to create an object through the base pointer.
Modified Nov 30, 2012
  • Gave the ability to limit the depth object_elemetList() goes into the structure and states <- MAX DEPTH REACHED to the right of the object's address.
These were added sometime between Nov 30 and Dec 3, 2012
  • Objects show up with hex addresses to aid in debugging.
  • Stops from infinitely recursing on an object if recursive references are there, and states either <- RECURSIVE REFERENCE or <- SELF REFERENCE to the right of the object's address.
  • Allows for not showing objects that have already previously been shown, and states <- ALREADY SHOWN to the right of the object's address.
Modified Dec 7, 2012
  • Referencing ClassCheck instead of ClassPermissions.
ClassPermissions - Classes dealing with class permissions (DEPRECATED - please use ClassCheck instead)
Depends on:
Object

Deprecated Dec 7, 2012

Hex - Converts a number to base 16
  • hex() - Converts a number to a hex number.
  • hex_dump() - dumps a part of memory in hex format.
  • hex_address() - returns an address passed in hex format with the length of the address based on the pointer size in use.
Depends on: Misc, ClassCheck

Modified Dec 7, 2012
  • Referencing ClassCheck instead of ClassPermissions.
Modified Nov 26, 2012
  • Added functions: hex_dump() and hex_address().
  • Fixed some issues with hex() and negative 64bit numbers.
  • Added a HEX.DEFAULT value.
  • Removed the const from the HEX constant class to increase performance.
DllCallCheck - checks to see if the call succeeded and reports failure.
  • _() - function to check if DllCall() succeeded or not.
Depends on: Hex

Modified Dec 1, 2012
  • No longer need to pass A_ScriptName and A_LineNumber. This is done automatically. The old style is still accepted however for backward compatibility.
Modified Jan 8, 2013
  • Removed reference to A_ScriptName and A_LineNumber in the usage documentation.
Added Nov 21, 2012

Ref - creates references to strings/numbers/objects
  • ref() - creates a reference of a string/number/object.
  • refs() - creates an array of a mixture of strings/numbers/objects.
  • isRef() - tests to see if variable is a ref.
  • refsWithMinSize() - creates an array of a mixture of strings/numbers/objects.
  • refFix() - fixes variables who's value could change the length of the string it contains.
  • ref_example() - example of how to use ref objects.
Depends on: Object, Misc

Modified Nov 26, 2012
  • Updated docs
  • Implemented member references can be reallocated from ref side.
  • Fixed potential string overrun when using unicode.
Misc - miscellaneous functions
  • FAIL() - reports a message, shows the stack and exits.
  • WARN() - reports a message, shows the stack and then continues on.
  • CallStack() - displays the call stack from latest call to oldest.
  • isNumber() - function to say if parameter is a valid number.
  • isInteger() - function to say if parameter is a valid integer.
  • repeat() - function to repeat a string a number of times.
  • memcpy() - wrapper for clib's memcpy() function.
  • memset() - wrapper for clib's memset() function.
Depends on DllCallCheck, ClassCheck

Modified Nov 26, 2012
  • Added repeat(), memcpy() and memset() functions.
Modified Nov 30, 2012
  • Fixed memcpy() which was calling the function with the wrong parameters.
Modified Dec 7, 2012
  • Added WARN() function.
  • Added documentation.
  • Referencing ClassCheck instead of ClassPermissions.
Added Nov 26, 2012
OutputDebug - debug output function
  • OutputDebug() - this fixes a problem with OutputDebug/WIN32 OutputDebugString() function which will not allow a string to be longer than 32k-2 characters long. Yeah, I dumped something that big. tongue.png
Added Dec 7, 2012
ClassCheck - Classes dealing with checking some coding with classes
  • checkMemberExists - alerts if a member is accessed that doesn't already exists. (previously known as checkExistance from ClassPermissions library)
  • checkMemberReadOnly - alerts if a member is being written to (previously known as const from ClassPermissions library).
  • checkMemberExistsReadOnly - alerts if a member is being written to or if a member is being accessed that doesn't already exist. (previously known as checkExistenceConst from ClassPermissionslibrary)
  • checkCallNameExists - alerts if a member function is called which doesn't exist.
  • checkCallNameExistsMemberExists - combines checkCallNameExists with checkMemberExists
  • checkCallNameExistsMemberReadOnly - combines checkCallNameExists with checkMemberReadOnly
  • checkCallNameExistsMemberExistsReadOnly - combines checkCallNameExists with checMemberExistsReadOnly
Modified Dec 7, 2012
  • Added documentation.
Added Nov 26, 2012
C - C interface library ALPHA
  • Definition of types:
    • c.typedef() - define a typedef.
    • c.struct() - define a struct.
    • c.union() - define a union.
    • c.define() - define a macro.
  • Instantiation of objects:
    • c.object class - c type object wrapper, use new c.object(typename) to create a c object in AHK_L.
    • c.objectArray class - c type object wrapper, use new c.objectArray(typename, sizeOfArray) to create a c object array type in AHK_L.
    • c.objectPointer class - c type object wrapper, use new c.object(typename, indirectionCount) to create a c object pointer type in AHK_L.
    • c.objectArrayOfPointers class - c type object wrapper, use new c.object(typename, sizeOfArray, indirectionCount) to create a c object array of pointers type in AHK_L.
  • Miscelanious functions:
    • c.sizeof() - get the size of a type or a c.object.
    • c.isTypeDefined() - states if the type has already been defined.
    • c.object.Set() - Sets the base object's value to another value.
    • c.object.Get() - Gets the base objects's value.
    • c.object.elementList() - list the elements in a c.object instance.
    • c.use() - use release or debug code. Release is faster, but debug has more checks. Both are still fast!
    • c.test1() - a test to show how it's done. smile.png
Depends on DllCallCheck, Misc, Lexer

This project is to create an interface library with C that is both easy to use and fast. Currently, this library creates C types and is now ~33% faster when run in release mode, compared to structs that are made by the _Struct library by HotKeyIt, which is a great library BTW. However, due to it not working when used with in one of my compiled scripts for some unknown reason to make a window semitransparent and that I wanted to have more safety features and I thought it would be a cool thing to do smile.png, I decided to make my own. It should be mostly compatible in usage to it and also has several additions such as:
  • Type namespace for embedded types, e.g. struct within a struct, doesn't pollute the global namespace.
  • Will tell you if you try and access a member that doesn't exist, informing you of errors ahead of time.
  • Listing elements in a c.object. Great for debugging purposes.
  • Allows iterating over an objects members or an arrays elements using the for key, value] in cobject syntax.
  • Parses C style typedefs, structs, unions, arrays.
  • Has a minimal macro preparser.
Incompatibilities that exist between _Struct and this library are:
  • Type creation:
    Currently, types are created once per process. A second type of the same name cannot be made. This is by design as it increases throughput by making it so that the type need not be parsed every time. Once parsed, its definition stays in memory for the life of the process. To create a struct such as a rect:
    c.struct("rect { int left, top, bottom, right; }")
    Note that this is C compatible syntax. One can almost cut and paste from the MSDN page.
    From the MSDN page:
    typedef struct _RECT {
      LONG left;
      LONG top;
      LONG right;
      LONG bottom;
    } RECT, *PRECT;
    How it could be coded:
    c.typedef("int LONG") ; LONG type needs to be defined using typedef to make this work.
    c.typedef("
    (
    struct _RECT {
      LONG left;
      LONG top;
      LONG right;
      LONG bottom;
      } RECT, *PRECT;
    )")
    Note: Anonymous types are now allowed!!.
    You can now create arrays, pointers and arrays of pointers of already defined types. This requires no parsing so is extreamly fast! Instead of creating a new c.object, you create a new c.objectArray, c.objectPointer or c.objectArrayOfPointers.
  • Definitions:
    As this is to eventually parse C code headers, it is incompatible with the specification that _Struct uses. This may change if people want it.
Modified Nov 30, 2012
  • Allow for creating base c types e.g. int, float, etc. e.g. c_int := new c.object("int")
  • The setting and getting of base type objects can be done by using .Get() and .Set(value) member functions for c.object's. e.g. c_int.Set(5) or c_int.Get(). This is also useful for when you have an object you wish to copy the contents over from another object, but it is at the lowest level. E.g.
    c.struct("numbers { int a, b, c }")
    a := new c.object("numbers") ; all values default to 0
    d := new c.object("numbers", )
    a.Set(d)
    a.Set({a: 1, c: 3}) ; assigns a.a to 1 and a.c to 3
  • Fixed ambiguity allowing the assignment of a c.object's initial value from the constructor, in case the c.object is a base numeric type.
    New syntax is:
    x := new c.object("int", C.ASSIGN_VALUE, 6)
    y := new c.object("int", C.ASSIGN_ADDRESS, address)
    
    Complex types such as structs and unions as well as array types can still be initialised using the old syntax (these are all equivalent):
    c.struct("mystruct { int a, b, c; }")
    x := new c.object("mystruct", {a: 1, b: 2, c: 3})
    x := new c.object("mystruct", {1: 1, 2: 2, 3: 3})
    x := new c.object("mystruct", {2: 2, 1: 1, 3: 3})
    x := new c.object("mystruct", )
  • Can now iterate over members of a struct/union or over the elements of an array using the for index, in object syntax.
    Added more checks to give programmer more information as to what went wrong.
  • Can now jump between Release and Debug code using c.use("ReleaseCode") or c.use("DebugCode").
    • ReleaseCode doesn't have as many checks as it assumes its internal data structures are valid and not being changed by external influences. It also has optimised code to speed things up.
    • Such optimisations are function unrolling, and removal of c.ndebug statements.
    • The debug version is a little faster on getting and about on par for setting elements in structures and unions then with _Struct.
    • The release version is about 33% faster then _Struct.
  • This library is now entirly not case sensitive.
  • This has all base types except for strings.
  • Unions and structs have been tested as well as their anonymous equivalents.
  • Understands all the types used in AHK except for Str.
Modified Dec 17, 2012
  • Added the use of a true lexer along side of the current one to compare performance. Performance appears to be comparable. Will have to do further testing before replacing old lexer with new one.
Modified Jan 8, 2013
  • Added tokelex class usage for testing.
Things to do:
  • Get it so that it understands function pointers.
  • Get it to parse an entire header file.
  • Figure out what to do with the Str type. BSTR?
  • Anonymous types need to be made to help in migrating others who use only anonymous types in their code previously.
  • Allow creating transient types, like arrays. DONE
  • Accept and ignore comments. Done in new Lexer implementation
  • Allow for specifying the minimum size of a type so that object which are just headers, can have a body.
  • More...?
Documentation on usage is inside the file.

Added Dec 17, 2012
Lexer - lexical analyzer class
  • Get Functions:
    • Get() - gets the current token.
    • GetPrev() - gets the previous token.
    • GetNext() - gets the next token.
    • IncGet() - moves the pointer forward and gets that token.
    • GetInc() - gets the current token and moves the pointer forward.
    • DecGet() - moves the pointer backward and gets that token.
    • GetDec() - gets the current token and moves the pointer backwards.
    • [x] - gets the token at offset x.
  • Hold Token Functions:
    • HoldTokens() - ensures that the tokens don't go stale (are deleted from the token cache) allowing for backtracking.
    • HoldTokensRelease() - releases the tokens from being held.
    • HoldTokensRevert() - move token pointer to last time HoldTokens() was called.
  • Helper Functions:
    • tokenizer_dropMultiLineToken() - discards a multiline token's contents.
    • tokenizer_readMultiLineToken() - return a multiline token's contents.
  • Functions to Override:
    • tokenizer() - generates tokens
    • preparser() - preparses the tokens potentially adding or removing tokens
    • someTokensAreNotIgnored() - states if the some of the tokens are useful (i.e. not ignored).
Depends on Misc, ClassCheck and LineReader

This is an abstract class that converts a text stream into a series of tokens that can be processed by a parser, but doesn't implement how the tokens are represented. That is up to the class that extends it.

It attempts to be very fast, as fast as I can get a scripting language to be. It is now used by the C.ahk library if you wish to see it in action. It is about as fast as the original parser was but is far more flexible and exact.

Again usage documentation is imbedded in the comments of the file.

Modified Jan 8, 2013
  • Slightly improved efficency to holdToken functions.
LineReader - line buffered stream class
  • General Use Functions:
    • GetLine() - gets the line from the buffered stream.
  • Information Functions:
    • Source() - gets a string stating the source of the data stream.
    • WhatAndWhereAmI() - get a string stating what source and where in the source the last GetLine() resulted in.
    • getContext() - gets a string stating the context (what is currently being buffered, what line numbers they are and what lines are in the middle of being processed)
    • diagnosticInfo() - gets a string with WhatAndWhereAmI() and getContext() info in it.
  • Functions to Override:
    • Source() - Where the buffered stream is coming from
    • UpdateBuffer() - updates the buffer with content beyond the currently buffered content.
This allows for getting consecutive lines from a text data stream. It understands \r\n, \n\r, \n, \r as new lines, even if the file got partially converted by something like cygwin's sed causing a mixture of both to creep in. It is designed for speed and ease of use (as much as could be allowed with these conflicting criteria).

Added Jan 8, 2013
tokelex - tokenizer/lexical analyzer class
  • General Use Functions:
    • tokelex.register() - register information relavent to a tokenizer/lexer.
    • new tokelex() - create a new tokenizer/lexer.
    • string() - tokenize/lex a string.
    • openFile() - tokenize/lex a file's contents.
    • tokenAvailable() - determines if a token is available.
    • [x] - gets the token at offset x.
  • Hold Token Functions:
    • HoldTokens() - ensures that the tokens don't go stale (are deleted from the token cache) allowing for backtracking.
    • HoldTokensRelease() - releases the tokens from being held.
    • HoldTokensRevert() - move token pointer to last time HoldTokens() was called.
Depends on Misc

This class library combines the speed of my original tokenizer I used in my C interface library and the flexibility of the lexer in my Lexer class. It does not buffer on lines, and it does not have a preparser. But what it does have is speed.

In tokenizer mode, this goes about 1.8 times the speed of the Lexer class. In lexer mode, it goes about 1.3 times that baseline speed. This is still not as fast as my original tokenizer (about 2.3 times the baseline). The reason for this is still unclear as I am using very similar code. I'm guessing that it has something to do with the newing of the object, and possibly the overhead of a function call or two.

More information including usage is in the comments embedded in the file.


I'll post more here as I create more functions that I think will be of use.


Adrian Hawryluk

my library base
AHK_L is the bomb! With a whole lot of bug fixes, Unicode support, associative array objects, array like objects, classes and variadic functions, why wouldn't you switch?


AutoHotkeyDragon
  • Members
  • 90 posts
  • Last active: Sep 01 2013 11:06 PM
  • Joined: 20 Oct 2012
Nice! Looking forward to using these!
AHKDragon

—I should be able to help with your AHK needs, unless it has something to do with anything GUI or complex. I hold no guarantees that I WILL be able to help, though.—

adrianh
  • Members
  • 616 posts
  • Last active: Apr 07 2016 03:35 PM
  • Joined: 28 Oct 2012
Thanks, let me know if there is anything that I missed.


Adrian

my library base
AHK_L is the bomb! With a whole lot of bug fixes, Unicode support, associative array objects, array like objects, classes and variadic functions, why wouldn't you switch?


Coco
  • Members
  • 697 posts
  • Last active: Oct 31 2015 07:26 PM
  • Joined: 27 Jul 2012
Hi Adrian,
Nice lib. Btw, Object.ahk does not contain the function "object_getBase()".
Thanks.

adrianh
  • Members
  • 616 posts
  • Last active: Apr 07 2016 03:35 PM
  • Joined: 28 Oct 2012
Thanks Coco,

Must have missed it when I reuploaded. It's there now.


Adrian

my library base
AHK_L is the bomb! With a whole lot of bug fixes, Unicode support, associative array objects, array like objects, classes and variadic functions, why wouldn't you switch?


Coco
  • Members
  • 697 posts
  • Last active: Oct 31 2015 07:26 PM
  • Joined: 27 Jul 2012
ThanksPosted Image

adrianh
  • Members
  • 616 posts
  • Last active: Apr 07 2016 03:35 PM
  • Joined: 28 Oct 2012
It's interesting to see that object.ahk is the most well received file...


Adrian

my library base
AHK_L is the bomb! With a whole lot of bug fixes, Unicode support, associative array objects, array like objects, classes and variadic functions, why wouldn't you switch?


adrianh
  • Members
  • 616 posts
  • Last active: Apr 07 2016 03:35 PM
  • Joined: 28 Oct 2012
Added Misc and Ref libraries.

my library base
AHK_L is the bomb! With a whole lot of bug fixes, Unicode support, associative array objects, array like objects, classes and variadic functions, why wouldn't you switch?


Coco
  • Members
  • 697 posts
  • Last active: Oct 31 2015 07:26 PM
  • Joined: 27 Jul 2012

Added Misc and Ref libraries.

Thanks Adrian, btw does ref() require misc() or is it for debugging only?

EDIT: Looked up the code, yes it does require it. I'll play with this and get back to you with my results/comments. Thanks.

Coco
  • Members
  • 697 posts
  • Last active: Oct 31 2015 07:26 PM
  • Joined: 27 Jul 2012
Can you show a sample on a dynamic function call on a function (with ByRef params), with a variable numbers of parameters passed?
EDIT: Tried some more tests, still impossible, as long as ByRef cannot reference array elements, nothing happens. Still needs eval() or AutoHotkey.dll to work around this.

adrianh
  • Members
  • 616 posts
  • Last active: Apr 07 2016 03:35 PM
  • Joined: 28 Oct 2012
Hmmmmmm, have you taken a look at the ref_test()?

Do you mean dynamic or variadict functions?


Adrian

my library base
AHK_L is the bomb! With a whole lot of bug fixes, Unicode support, associative array objects, array like objects, classes and variadic functions, why wouldn't you switch?


adrianh
  • Members
  • 616 posts
  • Last active: Apr 07 2016 03:35 PM
  • Joined: 28 Oct 2012
Btw, ref would supersed byref. In other words, you don't need byref for this to work. Let me know what in the documentation you find hard to understand.


Adrian

my library base
AHK_L is the bomb! With a whole lot of bug fixes, Unicode support, associative array objects, array like objects, classes and variadic functions, why wouldn't you switch?


Coco
  • Members
  • 697 posts
  • Last active: Oct 31 2015 07:26 PM
  • Joined: 27 Jul 2012
Hi Adrian, I like ref() very much..btw, at first launch, I got the "functions cannot contain functions" error, I think it is somewhere in the ref_test(). Maybe some missing brace, or something. You might want to check on that. But so far, it's good..Posted Image

adrianh
  • Members
  • 616 posts
  • Last active: Apr 07 2016 03:35 PM
  • Joined: 28 Oct 2012
Sorry, looks like I was on glue when I posted the ref.ahk file. Prior to posting the file, I had tried to encapsulate the test function, but encapsulated a function into that function so the file wouldn't even run. I apologise for that. I've verified that the file now works and updated the file.

Sorry for the inconvenience.


Adrian

my library base
AHK_L is the bomb! With a whole lot of bug fixes, Unicode support, associative array objects, array like objects, classes and variadic functions, why wouldn't you switch?


adrianh
  • Members
  • 616 posts
  • Last active: Apr 07 2016 03:35 PM
  • Joined: 28 Oct 2012

Hi Adrian, I like ref() very much..btw, at first launch, I got the "functions cannot contain functions" error, I think it is somewhere in the ref_test(). Maybe some missing brace, or something. You might want to check on that. But so far, it's good..Posted Image

Ahhh, so you got it to work now? I've just updated it complete with examples


Adrian

my library base
AHK_L is the bomb! With a whole lot of bug fixes, Unicode support, associative array objects, array like objects, classes and variadic functions, why wouldn't you switch?