Jump to content

Named arguments in function call - any ideas


Myicq
 Share

Recommended Posts

I have a project where I wish to create a layout file for a drawing program using AutoIT.

The format for this program is simple: header, objects (1..n), properties. Most of it, I have in control.

But I need an idea about how best to add the objects. Here, an object has some properties such as coordinate, font etc. My idea is to call a function like add_object() which will add with default parameters.

Now to my question: how can I "override" parameters in the function call ? I do not know which parameters will be overridden, this depends on user choices. So thereby I do not know the number of parameters in my function call.

Do anyone have an idea about how to do achieve something like this, which is inspired from Perl

; pseudocode function call:
add_object(
    'xpos' => '123',
    'font' => 'Arial',
    'rotation' => '90' )   ; the remaining parameters will be default

; pseudo code
func add_object(byref $paramsettings)
  $original = get_default_object()   ; first load a default object type
   for each $key ($paramsettings)
       $original[$key] = $paramsettings[$key]   ; override default here
   next
   write_out_object($original)   ; now with modified original
endfunc

I have looked at but I am not 100% sure how to pass as an argument and (specifically) how to check which keys are passed ? (as in "for each $keys in $passed_array")

Any help welcomed.

I am just a hobby programmer, and nothing great to publish right now.

Link to comment
Share on other sites

Your post makes me think that you'd be better looking at AutoIt object for your objects manipulations and towards SQLite for storage/query. Of course this is an out of the blue wild guess unless more requirements/constraints are thrown.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

i love this UDF too, its minimalistic and straight.

So what about defining a func which fills an AssoArray with standard values.

Then if you want to make an custom object you call the function, then change the values you want, then call the "make Object" function.

You dont event need to pass arguments as the AssoArray is global accessible.

#include <AssoArrays.au3>

_SetDefault()
x("obj.xpos",123)
x("obj.font",'Arial')
x("obj.rotation",90)
x_display()

write_out_object()

Func _SetDefault()
    x("obj.xpos",0)
    x("obj.ypos",0)
    x("obj.font",'Arial')
    x("obj.rotation",0)
    x("obj.edge",10)
EndFunc


Func write_out_object()
    DrawObj(x("obj.xpos"),x("obj.ypos"))
    RotateObj(x("obj.rotation"))
    ....
EndFunc
Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...