Code Monkey home page Code Monkey logo

autoitobject-internal's Introduction

AutoItObject Internal

Provides easy object creation via IDispatch interface.

Example

#include "AutoItObject_Internal.au3"
$myCar = IDispatch()
$myCar.make = 'Ford'
$myCar.model = 'Mustang'
$myCar.year = 1969
$myCar.__defineGetter('DisplayCar', DisplayCar)

Func DisplayCar($oThis)
	Return 'A Beautiful ' & $oThis.parent.year & ' ' & $oThis.parent.make & ' ' & $oThis.parent.model
EndFunc

MsgBox(0, "", $myCar.DisplayCar)

The way this library implements objects is to mimic javascript object behavior and functionality.

This approach was chosen for it's ease of use and for developers to be able to "jump right in" without learning a whole new syntax.

Comparing AutoItObject Internal to Other options

Feature AutoItObject-Internal AutoItObject UDF OOPEAu3 Map
getters ✔️
setters ✔️
destructors ✔️⚠️¹ ✔️
inheritance ✔️⚠️² ✔️
supports all au3 var types ✔️ ✔️
native windows dlls and AutoIt only ✔️ ✔️ ✔️
dynamic number of method parameters ✔️ ➖³
registering objects in the ROT ✔️ ✔️
extending/editing UDF object logic AutoIt c++ AutoIt

¹ destructors are not triggered on script shutdown.

² this is done by using the __assign method see #1

³ only for the constructor

autoitobject-internal's People

Contributors

genius257 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

autoitobject-internal's Issues

Heavy usage of DllCallbackRegister can result in crash

#include "AutoItObject_Internal.au3"

For $i=0 To 10000
    ConsoleWrite($i&@CRLF)
    $o = IDispatch()
Next

On my test PC, around "8958" AutoIt crashes.
AutoIt3.exe ended.rc:-1073741819

The issue itself is with AutoIt3 itself, but AutoItObject-Internal can avoid it, mostly.

A solution may be to change the way the default parameters in the IDispatch function are used. Instead of calling DllCallbackRegister every time, the defaults should only be created once internally in the function Local Static $... and used that way instead.

To also reduce this issue for cases with custom parameters, maybe check if variable is int (Int32 is the return type from a DllCallbackRegister call) or a Ptr (the return type from DllCallbackGetPtr) and use them instead.

Event sink

Event sink support would be great, allowing AutoIt3 to use ObjEvent with the objects.
As an alternative, a extension of the script, either as a new repository or an extra file with the Event sink availability on the IDispatch objects.

var access so long

code for tests https://pastebin.com/iahENe7v
access to variable take 100x longer than to AutoItObject UDF
and 780x longer than to simple Variable

result:
Variable cycle 10k => 1.991 ms || _console_time
Variable one => 0.006 ms || _console_time

AutoItObject UDF FirstObj cycle 10k => 15.763 ms || _console_time
AutoItObject UDF FirstObj one => 0.008 ms || _console_time

AutoItObject UDF SecondObj cycle 10k => 15.696 ms || _console_time
AutoItObject UDF SecondObj one => 0.006 ms || _console_time

AutoItObject Internal cycle 10k => 1554.424 ms || _console_time
AutoItObject Internal one => 0.162 ms || _console_time

Calling IDispatch object as function, results in first element

#include "AutoItObject_Internal.au3"
$oIDispatch = IDispatch()

$oIDispatch.a = "a"
$oIDispatch.b = "b"

ConsoleWrite($oIDispatch()&@CRLF); a

A fix would be looking for a property with name as empty string, if id 0 is received.
Function for property lookup need to modify return index +1

Feature request: Create a clone of an object

Would be nice to could write

...
$oFoo2=$oFoo1.clone
...

Example
how it works at the moment (which in general is fine but would be nice to quickly clone) is that a var references another object where you sometimes want a copy/clone

#include <AutoItObject_Internal.au3>
$cFoo=IDispatch()
$oFoo1=$cFoo
$oFoo2=$cFoo

$oFoo1.Property1="Nice"

;~ And now the fun comes as they both point to same object

consolewrite($oFoo2.Property1)

Endgoal I would like to reach is that you have

;~ Have a generic method reference that is shared
$cFoo.Method1 = cFoo_Method1
func cFoo_Method1
;~ whatever we want to have shared as a method printing a property of the current object
ConsoleWrite($self.parent.Property1)
endfunc

$oFoo1=cFoo.clone
$oFoo2=cFoo.clone

;~ Have independent propertyvalues
$oFoo1.Property1="Hello world 1"
$oFoo2.Property1="Hello world 2"

$oFoo1.Method1
$oFoo2.Method1

"previous declared as const"

Hello,
Funny thing, i did run it once - it workd, i compiled it once - it workd.
Then i tried to run it again, and this happens now everytime i try to run it:

`"C:\Users\ataltambanis\Desktop\Autoit 3\Projekte\GITHUB\Internal-Framework\Framework#unused yet\AutoItObject-Internal\AutoItObject_Internal.au3"(20,63) : error: $S_OK previously declared as a 'Const'.
If Not IsDeclared("S_OK") Then Global Const $S_OK = 0x00000000

"C:\Users\ataltambanis\Desktop\Autoit 3\Projekte\GITHUB\Internal-Framework\Framework\#unused yet\AutoItObject-Internal\AutoItObject_Internal.au3"(21,73) : error: $E_NOTIMPL previously declared as a 'Const'.
If Not IsDeclared("E_NOTIMPL") Then Global Const $E_NOTIMPL = 0x80004001
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\ataltambanis\Desktop\Autoit 3\Projekte\GITHUB\Internal-Framework\Framework\#unused yet\AutoItObject-Internal\AutoItObject_Internal.au3"(22,81) : error: $E_NOINTERFACE previously declared as a 'Const'.
If Not IsDeclared("E_NOINTERFACE") Then Global Const $E_NOINTERFACE = 0x80004002
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\ataltambanis\Desktop\Autoit 3\Projekte\GITHUB\Internal-Framework\Framework\#unused yet\AutoItObject-Internal\AutoItObject_Internal.au3"(23,73) : error: $E_POINTER previously declared as a 'Const'.
If Not IsDeclared("E_POINTER") Then Global Const $E_POINTER = 0x80004003
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\ataltambanis\Desktop\Autoit 3\Projekte\GITHUB\Internal-Framework\Framework\#unused yet\AutoItObject-Internal\AutoItObject_Internal.au3"(24,69) : error: $E_ABORT previously declared as a 'Const'.
If Not IsDeclared("E_ABORT") Then Global Const $E_ABORT = 0x80004004
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\ataltambanis\Desktop\Autoit 3\Projekte\GITHUB\Internal-Framework\Framework\#unused yet\AutoItObject-Internal\AutoItObject_Internal.au3"(25,67) : error: $E_FAIL previously declared as a 'Const'.
If Not IsDeclared("E_FAIL") Then Global Const $E_FAIL = 0x80004005
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\ataltambanis\Desktop\Autoit 3\Projekte\GITHUB\Internal-Framework\Framework\#unused yet\AutoItObject-Internal\AutoItObject_Internal.au3"(26,83) : error: $E_ACCESSDENIED previously declared as a 'Const'.
If Not IsDeclared("E_ACCESSDENIED") Then Global Const $E_ACCESSDENIED = 0x80070005
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\ataltambanis\Desktop\Autoit 3\Projekte\GITHUB\Internal-Framework\Framework\#unused yet\AutoItObject-Internal\AutoItObject_Internal.au3"(27,71) : error: $E_HANDLE previously declared as a 'Const'.
If Not IsDeclared("E_HANDLE") Then Global Const $E_HANDLE = 0x80070006
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\ataltambanis\Desktop\Autoit 3\Projekte\GITHUB\Internal-Framework\Framework\#unused yet\AutoItObject-Internal\AutoItObject_Internal.au3"(28,81) : error: $E_OUTOFMEMORY previously declared as a 'Const'.
If Not IsDeclared("E_OUTOFMEMORY") Then Global Const $E_OUTOFMEMORY = 0x8007000E
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\ataltambanis\Desktop\Autoit 3\Projekte\GITHUB\Internal-Framework\Framework\#unused yet\AutoItObject-Internal\AutoItObject_Internal.au3"(29,79) : error: $E_INVALIDARG previously declared as a 'Const'.
If Not IsDeclared("E_INVALIDARG") Then Global Const $E_INVALIDARG = 0x80070057
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\ataltambanis\Desktop\Autoit 3\Projekte\GITHUB\Internal-Framework\Framework\#unused yet\AutoItObject-Internal\AutoItObject_Internal.au3"(30,79) : error: $E_UNEXPECTED previously declared as a 'Const'.
If Not IsDeclared("E_UNEXPECTED") Then Global Const $E_UNEXPECTED = 0x8000FFFF
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Users\ataltambanis\Desktop\Autoit 3\Projekte\GITHUB\Internal-Framework\Framework\#unused yet\AutoItObject-Internal\AutoItObject_Internal_Example.au3 - 11 error(s), 0 warning(s)`

Edit: i tried to run it now again multiple times, and it workd again, haha.

__has

a __has method for the IDispatch object, to check if an object has a key, instead of using __get and either creating the key or producing a COM error if the object is frozen.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.