The Croc Programming Language
Functions

Macros

#define croc_function_new(t, name, maxParams, func, numUpvals)   (croc_pushCurEnvironment(t), croc_function_newWithEnv((t), (name), (maxParams), (func), (numUpvals)))
 

Functions

word_t croc_function_newWithEnv (CrocThread *t, const char *name, word_t maxParams, CrocNativeFunc func, uword_t numUpvals)
 
word_t croc_function_newScript (CrocThread *t, word_t funcdef)
 
word_t croc_function_newScriptWithEnv (CrocThread *t, word_t funcdef)
 
word_t croc_function_pushEnv (CrocThread *t, word_t func)
 
void croc_function_setEnv (CrocThread *t, word_t func)
 
word_t croc_function_pushDef (CrocThread *t, word_t func)
 
uword_t croc_function_getNumParams (CrocThread *t, word_t func)
 
uword_t croc_function_getMaxParams (CrocThread *t, word_t func)
 
int croc_function_isVararg (CrocThread *t, word_t func)
 
uword_t croc_function_getNumReturns (CrocThread *t, word_t func)
 
uword_t croc_function_getMaxReturns (CrocThread *t, word_t func)
 
int croc_function_isVarret (CrocThread *t, word_t func)
 
int croc_function_isNative (CrocThread *t, word_t func)
 

Detailed Description

Functions which operate on function closures.

Macro Definition Documentation

#define croc_function_new (   t,
  name,
  maxParams,
  func,
  numUpvals 
)    (croc_pushCurEnvironment(t), croc_function_newWithEnv((t), (name), (maxParams), (func), (numUpvals)))

Like croc_function_newWithEnv, except it uses the current environment namespace, so the only values it expects on the stack are any upvalues.

Function Documentation

word_t croc_function_newWithEnv ( CrocThread t,
const char *  name,
word_t  maxParams,
CrocNativeFunc  func,
uword_t  numUpvals 
)

Creates and pushes a new native function closure, expecting the environment on top of the stack and any upvals below that.

The environment namespace and any upvals are popped and the function is pushed in their place.

Parameters
nameis the name to give the function.
maxParamsis the maximum allowable parameters (after the 'this' parameter), or -1 to make it variadic.
funcis the native function itself.
numUpvalsis how many upvalues will be associated with this closure. There must be this many values on the stack under the environment namespace on top.
Returns
the stack index of the pushed value.
word_t croc_function_newScript ( CrocThread t,
word_t  funcdef 
)

Creates and pushes a new script function closure from the function definition in slot funcdef, and uses the current function environment (or the globals if there is none) as the closure's environment.

There is no way to create a script closure through the native API from a funcdef which has upvalues. Also, it is an error to create a closure with a different environment namespace than it was instantiated with initially.

Returns
the stack index of the pushed value.
word_t croc_function_newScriptWithEnv ( CrocThread t,
word_t  funcdef 
)

Same as croc_function_newScript, but expects the environment namespace on top of the stack.

It will be popped and the function will be pushed in its place.

Returns
the stack index of the pushed value.
word_t croc_function_pushEnv ( CrocThread t,
word_t  func 
)

Pushes the environment namespace of the function at slot func.

Returns
the stack index of the pushed value.
void croc_function_setEnv ( CrocThread t,
word_t  func 
)

Sets the environment namespace of the native function closure at slot func.

Expects the new environment on top of the stack, and pops it.

You cannot set the environment namespace of script closures.

word_t croc_function_pushDef ( CrocThread t,
word_t  func 
)

Pushes the funcdef of the function closure at func, or pushes null if func is a native function.

Returns
the stack index of the pushed value.
uword_t croc_function_getNumParams ( CrocThread t,
word_t  func 
)
Returns
the number of non-variadic parameters that the function at func takes.
uword_t croc_function_getMaxParams ( CrocThread t,
word_t  func 
)
Returns
the maximum number of parameters that the function at func can be called with. For variadic functions, this will be an absurdly large number.
int croc_function_isVararg ( CrocThread t,
word_t  func 
)
Returns
nonzero if the function at func is variadic.
uword_t croc_function_getNumReturns ( CrocThread t,
word_t  func 
)
Returns
the number of non-variadic values that the function at func returns.
uword_t croc_function_getMaxReturns ( CrocThread t,
word_t  func 
)
Returns
the maximum number of values that the function at func can return. For variadic return functions, this will be an absurdly large number.
int croc_function_isVarret ( CrocThread t,
word_t  func 
)
Returns
nonzero if the function at func has variadic returns.
int croc_function_isNative ( CrocThread t,
word_t  func 
)
Returns
nonzero if the function at func is native.