function

Reference to Lua function in C/C++

I have a functions nested relatively deeply in a set of tables. Is there a way in C/C++ to get a "reference" to that function and push that (and args) onto the stack when I need to use it? ...

Lua: Get the literal name of the parameter

For example, function test (a) name = nameof(a) print(name) end test(def) --should print "def" Are there any lua tricks to implement something similar to the above? ...

C++ implicit function calls

Will c++ implicit function calls be a feature of C++0x ? It is an interesting feature, but I haven't seen any progress on this and the GCC C++0x page didn't even mention it. See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1611.pdf ...

Lua Closures in implementing a DSL

Lua has a really nice no-parenthesis call syntax that coupled with function closures allow me to write the following local tag = 1 function test(obj) return function(str) return function (tbl) tbl.objtag = tag tbl.objname = str return tbl end end end test (tag) "def" { } test tag ...

How can i store a bunch of jquery commands in a function that i can call with click event.

Currently i have this: $(".splitCol").click(function () { $.cookie('whichColumn', 'split'); $(".threeCol .active").removeClass("active"); $(".leftCol .active").removeClass("active"); $(".splitCol span").addClass("active"); $(".threeColumns li:eq(3)").removeClass("first"); $(".threeColumns li:eq(6)").remo...

Is it possible to convert a PHP function's parameter list to an array?

Suppose I have a function: function my_function($a, $b, $c) { ... } I want to be able to play with my parameter list as if it were an array - as with here, using a fake $parameter_list variable: function my_function($a, $b, $c) { foreach ($parameter_list as $value) { print $value."\n"; } ... } How can I do t...

What's the difference between virtual function instantiations in C++?

What's the difference between the following two declarations? virtual void calculateBase() = 0; virtual void calculateBase(); I read the first one (=0) is a "pure abstract function" but what does that make the second one? ...

Why is my join on a JavaScript array failing?

I have a function that accepts multiple arguments (only one is defined in the function though) var getSearchFields = function(method) { console.log(arguments); // this prints them out nicely into the console var args = arguments; var argsString = args.join('/'); // I expect 'arg1/arg2/arg3', instead I get 'args.join is no...

Working with time in the iPhone

I have two arrays with time values in them in this format. 00:00:00 which is minutes:seconds:miliseconds. Can someone show me any easy way of adding an subtracting these values? I know I can if I break them down but I am looking for a way to do it without of code. I can get the last values which is what I want to work with like this ...

Is there any way to get a referring function's name in PHP?

I have a function that is often called inside of other functions, and I'd like to be able to find out automatically what the name of the referring function (if any) was. Something like this: function do_something() { do_something_else(); } function do_something_else() { echo referring_function(); // prints 'do_something' } I...

OCaml: Default values for function arguments?

In PHP, default values for arguments can be set as follows: function odp(ftw = "OMG!!") { //... } Is there similar functionality in OCaml? ...

PHP equivalent for a python decorator?

I want to be able to wrap a PHP function by another function, but leaving its original name/parameter list intact. For instance: function A() { print "inside A()\n"; } function Wrap_A() { print "Calling A()\n"; A(); print "Finished calling A()\n"; } // <--- Do some magic here (effectively "A = Wrap_A") A(); Output:...

Is there a way in javascript to obtain the definition of a given function as a string, to be possibly modified and evaled?

I am trying to evaluate a function in a new context, ie, one that contains a certain word defined that does not exist in the scope. It is easy enough if I have the definition of the function as a string, but I would like to provide the ability to do this with a regular list of functions, like so: var funcs = { first: function() { ret...

How can I modify a 2d array passed to a function?

Why does the following code give me a segmentation fault? #define MAXROWS 10 #define MAXCOLS 10 void getInput (int *data[MAXROWS][MAXCOLS]) { int rows, cols; int curRow, curCol; printf ("How many rows and cols?"); scanf ("%d %d", rows, cols); for (curRow = 0; curRow < rows; curRow++) { for (curCol = 0; curCol < cols; curC...

variable-size type declared outside of any function

when declaring the two dimensional array int random[height][width]; and then using it in a function void populate(int random[height][width], int x, int y) gives the error variable-size type declared outside of any function. I know I'm doing something wrong, and that its something small. I just have a bad memory... ...

Python: Passing a class name as a parameter to a function?

class TestSpeedRetrieval(webapp.RequestHandler): """ Test retrieval times of various important records in the BigTable database """ def get(self): commandValidated = True beginTime = time() itemList = Subscriber.all().fetch(1000) for item in itemList: pass endTime = time() self....

How to examine the code of a function in R that's object class sensitive

Hello. I'm trying to write a function to do a particular job (in my case, analyse a data set for outliers) so the first things I want to do is look at how other people have done similar jobs. I can do this to load a particular package and examine the code of a function, but some functions seem to depend on what class of object you thro...

PHP best practices: repass variables from config file when calling functions or use global?

I have a program that I use on several sites. It uses require('config.php'); to set any site dependant variables like mysql connect info, paths, etc. Let's say that I use one of these site-dependant variables in a function, like $backup_path. This variable was initially declared in config.php, and does not appear in the main program fi...

How do I flag a function as being deprecated in an iPhone Objective C header file?

Hey guys, Does any one know how to do this? I'm guessing there's just some keyword I can stick after the function somewhere? EDIT: I would like for a compiler warning to be generated should anyone try and use the deprecated function, similar to the behavior seen in Apple's APIs. Cheers! Nick. ...

Where is function's declaration in bash?

In my script in bash, there are lot of included libs and I use functions declared in these files. Like this: #!/bin/bash . foo.inc . bar.inc . baz.inc function_1 function_2 function_3 EOF My question is how to learn which file include function_1 declaration? In runtime of this script. ...