# Function Signatures

**URL:** <https://forum.kirupa.com/t/function-signatures/184767>\
**Category:** flash\
**Created:** [April 7, 2006, 4:25pm UTC](https://forum.kirupa.com/t/function-signatures/184767 "2006-04-07T16:25:52Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jwopitz](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/jwopitz/32/1556_2.png) [@jwopitz](https://forum.kirupa.com/u/jwopitz)\
**Post date:** [April 7, 2006, 4:25pm UTC](https://forum.kirupa.com/t/function-signatures/184767/1 "2006-04-07T16:25:52Z")

</div>

Has anyone ever heard of a way to dynamically retrieve a function’s signature? Example:  
ActionScript Code:  
[FONT=Courier New][LEFT][COLOR=#000000] **function** [/COLOR] tester [COLOR=#000000]([/COLOR]p0:[COLOR=#0000FF]String[/COLOR], p1:[COLOR=#0000FF]Number[/COLOR], p2:[COLOR=#0000FF]Number[/COLOR], p3:[COLOR=#0000FF]MovieClip[/COLOR] …[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#808080]_//do stuff_[/COLOR]  
[COLOR=#000000]}[/COLOR]

[COLOR=#000000] **function** [/COLOR] getSignature COLOR=#000000[/COLOR]:[COLOR=#0000FF]Array[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#000000] **var** [/COLOR] parameter\_array:[COLOR=#0000FF]Array[/COLOR] = [COLOR=#000000] **new** [/COLOR] [COLOR=#0000FF]Array[/COLOR] COLOR=#000000[/COLOR];  
[COLOR=#808080]_//look at the parameter typeof requirements for tester ()_[/COLOR]  
[COLOR=#808080]_//build an array like using some sort of for in loop:_[/COLOR]  
parameter\_array[COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#FF0000]“String”[/COLOR]  
parameter\_array[COLOR=#000000][[/COLOR][COLOR=#000080]1[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#FF0000]“Number”[/COLOR]  
parameter\_array[COLOR=#000000][[/COLOR][COLOR=#000080]2[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#FF0000]“Number”[/COLOR]  
parameter\_array[COLOR=#000000][[/COLOR][COLOR=#000080]3[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#FF0000]“MovieClip”[/COLOR]

```
[COLOR=#0000FF]return[/COLOR] parameter_array;

```

[COLOR=#000000]}[/COLOR]  
[/LEFT]  
[/FONT]

---

<div class="post-metadata">

**Author:** ![B\_L\_U\_E](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@B\_L\_U\_E](https://forum.kirupa.com/u/B_L_U_E)\
**Post date:** [April 7, 2006, 4:29pm UTC](https://forum.kirupa.com/t/function-signatures/184767/2 "2006-04-07T16:29:56Z")

</div>

I’m not familiar with the term _function’s signature_. Does that mean the data type of a variable (String,Number,etc) ?

:cowboy:

---

<div class="post-metadata">

**Author:** ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)\
**Post date:** [April 7, 2006, 4:32pm UTC](https://forum.kirupa.com/t/function-signatures/184767/3 "2006-04-07T16:32:37Z")

</div>

wheres The Canadian when you need him?

---

<div class="post-metadata">

**Author:** ![mathew\_er](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@mathew\_er](https://forum.kirupa.com/u/mathew_er)\
**Post date:** [April 7, 2006, 4:41pm UTC](https://forum.kirupa.com/t/function-signatures/184767/4 "2006-04-07T16:41:26Z")

</div>

Dunno what you realy mean… There are two things in As that you mich be looking for… typeof and instanceof

```auto
var someVar:Number = 10;
trace(typeof someVar)
// returns number

```

and

```auto
import flash.geom.Rectangle;
var someObject:Rectangle = new Rectangle();
trace(typeof someObject)
// returns object
trace(someObject instanceof Rectangle)
// returns true

```

---

<div class="post-metadata">

**Author:** ![B\_L\_U\_E](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@B\_L\_U\_E](https://forum.kirupa.com/u/B_L_U_E)\
**Post date:** [April 7, 2006, 4:44pm UTC](https://forum.kirupa.com/t/function-signatures/184767/5 "2006-04-07T16:44:03Z")

</div>

If he does mean returning the data type of a variable, it would be like [AS]return typeof variable  
//orreturn instanceof variable[/AS]

---

<div class="post-metadata">

**Author:** ![jwopitz](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/jwopitz/32/1556_2.png) [@jwopitz](https://forum.kirupa.com/u/jwopitz)\
**Post date:** [April 7, 2006, 6:02pm UTC](https://forum.kirupa.com/t/function-signatures/184767/6 "2006-04-07T18:02:26Z")

</div>

So to answer so ?'s:

When I say function signature I mean knowing a function’s parameters, the typeof each parameter and the return type of the function. I need to get this information without actually calling the function.

I am familiar with both typeof and instance of.

Let me rephrase a few things. I need to know 1) how many parameters a function has and 2) the requested typeof each parameter in the function.

I need to do this without actually calling the function. I also need to do this dynamically.

---

<div class="post-metadata">

**Author:** ![mathew\_er](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@mathew\_er](https://forum.kirupa.com/u/mathew_er)\
**Post date:** [April 7, 2006, 6:53pm UTC](https://forum.kirupa.com/t/function-signatures/184767/7 "2006-04-07T18:53:54Z")

</div>

So everytime you call a function, make an array with types of parametres where the length of that array is also number of parametres… if you want to use different number of parametres in one function, then its harder. I searched for some parameter array, but it seem that nothing like that exist in AS so you would have to use only one paramtre (an array) and call all functions like

```auto
function someFunc(args:Array):Void {
	trace("total number of parametres: "+args.length);
	for (i=0; i<args.length; i++) {
		trace("parameter "+i+": "+args*);
	}
	// if you want to store these inforamation, then use
	// the function Ill declare below
	makeArray("someFunc", args);
}

someFunc(["par1", "par2", 3]);
trace(someFunc_array);
// 3 string string number

function makeArray(name:String, args:Array):Void {
	this[name+"_array"] = new Array();
	this[name+"_array"].push(args.length);
	for (i=0; i<args.length; i++) {
		this[name+"_array"].push(typeof args*);
	}
}

```

---

<div class="post-metadata">

**Author:** ![jwopitz](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/jwopitz/32/1556_2.png) [@jwopitz](https://forum.kirupa.com/u/jwopitz)\
**Post date:** [April 7, 2006, 7:27pm UTC](https://forum.kirupa.com/t/function-signatures/184767/8 "2006-04-07T19:27:45Z")

</div>

Here is the whole purpose of my problem. I made an ArgumentChecker which you can read about here:

[http://www.kirupa.com/forum/showthread.php?t=214908](http://www.kirupa.com/forum/showthread.php?t=214908)

Basically I want to take that one step further since that only applies to strings. Many people are going to read this and ask why I wouldn’t just do this or that. The simple answer is that I want to do this in a particular manner for the sake of learning.

So let me try an anology:

- You want to buy a funky new CD player that requires batteries. (the function to be inspected)
- You don’t know what type of batteries it requires (batteries = parameters)
- It does not say what type of batteries it requires and most people won’t know until they purchase the item and open it up (calling the function)
- you want to figure out what type of batteries it requires without buying and opening the item (looking at the parameters without calling the function)

So now you can see where this is going. I want to be able to:

1. peer into a targeted function (w/o calling it),
2. check the type casting of its required parameters,
3. use my argument checker to see if incoming parameters destined for the target function are type casted correctly,
4. correct them if needed based on the target functions signature,
5. pass the newly corrected parameters to the target function.

Someone here at work suggested that I check Reflection in teh as2lib but I wasn’t able to understand the documentation. Man I really hope this is possible. It would save a ton of work correcting crap that was created overseas, that I need to debug.

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [April 8, 2006, 12:52am UTC](https://forum.kirupa.com/t/function-signatures/184767/9 "2006-04-08T00:52:15Z")

</div>

> [@Defective](#):
>
> wheres The Canadian when you need him?

Well don’t I feel special 😊 - unfortunately what you are trying to do is impossible unless you rig something up which would be incredibly tedious and redundant mostly because Flash does the type checking for you. I suppose the moral of the story is: don’t pass the wrong type of argument ( 😉 ) and if you do, let Flash tell you the error 🙂
