Classes | Functions

LuaCocoa.h File Reference

#include <stdarg.h>
#include <stdbool.h>
#include <LuaCocoa/lua.h>
#include <LuaCocoa/lualib.h>
#include <LuaCocoa/lauxlib.h>
#import <Foundation/Foundation.h>

Go to the source code of this file.

Classes

class  LuaCocoa
 LuaCocoa is the primary class you use to bridge your Lua code with Objective-C (and vice-versa). More...

Functions

bool LuaCocoa_IsInstance (struct lua_State *lua_state, int stack_index)
 Returns true if an instance of an Obj-C class.
id LuaCocoa_CheckInstance (struct lua_State *lua_state, int stack_index)
 Returns an Obj-C instance or triggers a Lua error.
id LuaCocoa_ToInstance (struct lua_State *lua_state, int stack_index)
 Returns an Obj-C instance.
void LuaCocoa_PushInstance (struct lua_State *lua_state, id the_object)
 Pushes an Obj-C instance.
bool LuaCocoa_IsClass (struct lua_State *lua_state, int stack_index)
 Returns true if an Obj-C class.
Class LuaCocoa_CheckClass (struct lua_State *lua_state, int stack_index)
 Returns an Obj-C class or triggers a Lua error.
Class LuaCocoa_ToClass (struct lua_State *lua_state, int stack_index)
 Returns an Obj-C class.
void LuaCocoa_PushClass (struct lua_State *lua_state, Class the_class)
 Pushes an Obj-C class.
bool LuaCocoa_IsNSNumber (struct lua_State *lua_state, int stack_index)
 Returns true for integers, floats, booleans, and NSNumbers.
NSNumber * LuaCocoa_CheckNSNumber (struct lua_State *lua_state, int stack_index)
 Returns a NSNumber or triggers a Lua error.
NSNumber * LuaCocoa_ToNSNumber (struct lua_State *lua_state, int stack_index)
 Returns a NSNumber.
void LuaCocoa_PushUnboxedNSNumber (struct lua_State *lua_state, NSNumber *the_number)
 Pushes a Lua number converted from an NSNumber onto the stack (instead of pushing the NSObject through the bridge).
bool LuaCocoa_IsNSNull (struct lua_State *lua_state, int stack_index)
 Returns true if the object at the specified index is nil or NSNull.
NSNull * LuaCocoa_CheckNSNull (struct lua_State *lua_state, int stack_index)
 Returns NSNull or triggers a Lua error.
NSNull * LuaCocoa_ToNSNull (struct lua_State *lua_state, int stack_index)
 Returns NSNull.
bool LuaCocoa_IsNSString (struct lua_State *lua_state, int stack_index)
 Returns true for strings, numbers (which is always convertible to a string), and NSString.
NSString * LuaCocoa_CheckNSString (struct lua_State *lua_state, int stack_index)
 Returns a NSString or triggers a Lua error.
NSString * LuaCocoa_ToNSString (struct lua_State *lua_state, int stack_index)
 Returns a NSString.
void LuaCocoa_PushUnboxedNSString (struct lua_State *lua_state, NSString *the_string)
 Pushes a Lua string converted from an NSString onto the stack (instead of pushing the NSObject through the bridge).
__strong const char * LuaCocoa_ToString (struct lua_State *lua_state, int stack_index)
 If a NSString, returns C-string, or if C-string, returns C-string.
bool LuaCocoa_IsNSArray (struct lua_State *lua_state, int stack_index)
 Returns true for Lua arrays and NSArrays.
void LuaCocoa_PushUnboxedNSArray (struct lua_State *lua_state, NSArray *the_array)
 Converts a NSArray to a Lua array (table) and pushes it on the stack.
bool LuaCocoa_IsNSDictionary (struct lua_State *lua_state, int stack_index)
 Returns true for Lua tables and NSDictionaries.
void LuaCocoa_PushUnboxedNSDictionary (struct lua_State *lua_state, NSDictionary *the_dictionary)
 Converts a NSDictionary to a Lua table and pushes it on the stack.
bool LuaCocoa_IsPropertyList (struct lua_State *lua_state, int stack_index)
 Returns true for NSNumber/number, NSNull/nil, NSString/string, NSDictionary, NSArray, or a Lua table.
id LuaCocoa_ToPropertyList (struct lua_State *lua_state, int stack_index)
 Converts Lua types to Cocoa types.
void LuaCocoa_PushUnboxedPropertyList (struct lua_State *lua_state, id the_object)
 Converts Cocoa types to Lua types and pushes on the stack.
bool LuaCocoa_IsSelector (struct lua_State *lua_state, int stack_index)
 Returns true for selectors or selectors boxed in NSValues.
SEL LuaCocoa_CheckSelector (struct lua_State *lua_state, int stack_index)
 Returns a selector or triggers a Lua error.
SEL LuaCocoa_ToSelector (struct lua_State *lua_state, int stack_index)
 Returns a selector.
void LuaCocoa_PushSelector (struct lua_State *lua_state, SEL the_selector)
 Pushes a selector into Lua.
NSString * LuaCocoa_GetInfoOnFunction (lua_State *lua_state, const char *function_name, int *line_defined, int *last_line_defined)
 Helper function to get debug info on a Lua function.
NSString * LuaCocoa_ParseForErrorFilenameAndLineNumber (NSString *the_string, int *line_number)
 Helper function to parse a Lua error string and extract the filename and line number.
NSString * LuaCocoa_PcallLuaFunction (lua_State *lua_state, lua_CFunction lua_error_function, const char *lua_function_name, const char *parameter_signature,...)
 Convenience method to pcall functions in Lua and allows an error function to be specified.
NSString * LuaCocoa_PcallLuaFunctionv (lua_State *lua_state, lua_CFunction lua_error_function, const char *lua_function_name, const char *parameter_signature, va_list vl)
 Convenience method to pcall functions in Lua and allows an error function to be specified.
void LuaCocoa_PrependToLuaSearchPath (struct lua_State *lua_state, const char *search_path)
 Prepends a new path the Lua package search path.
void LuaCocoa_AppendToLuaSearchPath (struct lua_State *lua_state, const char *search_path)
 Appends a new path the Lua package search path.
void LuaCocoa_PrependToCSearchPath (struct lua_State *lua_state, const char *search_path)
 Prepends a new path the Lua/C package search path.
void LuaCocoa_AppendToCSearchPath (struct lua_State *lua_state, const char *search_path)
 Appends a new path the Lua/C package search path.
bool LuaCocoa_IsStruct (struct lua_State *lua_state, int stack_index)
 Returns true if the object is a struct.
bool LuaCocoa_IsStructWithName (struct lua_State *lua_state, int stack_index, const char *key_name)
 Returns true if the object is a struct of the named type you specify.
const char * LuaCocoa_GetStructName (struct lua_State *lua_state, int stack_index)
 Returns the name of the struct.
void * LuaCocoa_CheckStruct (struct lua_State *lua_state, int stack_index, const char *key_name)
 Returns a pointer to a struct or triggers a Lua error.
bool LuaCocoa_PushStruct (struct lua_State *lua_state, void *the_struct, const char *key_name)
 Pushes a copy of the struct passed in onto the stack.

Function Documentation

void LuaCocoa_AppendToCSearchPath ( struct lua_State *  lua_state,
const char *  search_path 
)

Appends a new path the Lua/C package search path.

Modifies the package.cpath to append the specified string. Should be in proper lua format: e.g. /Users/ewing/Library/Application Support/LuaCocoa/PlugIns/?.so This means you must explicitly include the ?.so (or whatever file extensions you use.)

Parameters:
lua_stateThe lua_State to operate on.
search_pathThe path to append.
void LuaCocoa_AppendToLuaSearchPath ( struct lua_State *  lua_state,
const char *  search_path 
)

Appends a new path the Lua package search path.

Modifies the package.path to append the specified string. Should be in proper lua format: e.g. /Users/ewing/Source/HG/LuaCocoa/Xcode/build/Debug/LuaCocoa.framework/Resources/?.lua This means you must explicitly include the ?.lua (or whatever file extensions you use.)

Parameters:
lua_stateThe lua_State to operate on.
search_pathThe path to append.
Class LuaCocoa_CheckClass ( struct lua_State *  lua_state,
int  stack_index 
)

Returns an Obj-C class or triggers a Lua error.

Returns an Obj-C class the specified index or triggers a Lua error.

Parameters:
lua_stateThe lua_State to operate on.
stack_indexThe index of the stack of the object you want to know about.
Returns:
The class.
id LuaCocoa_CheckInstance ( struct lua_State *  lua_state,
int  stack_index 
)

Returns an Obj-C instance or triggers a Lua error.

Returns an Obj-C instance at the specified index or triggers a Lua error.

Parameters:
lua_stateThe lua_State to operate on.
stack_indexThe index of the stack of the object you want to know about.
Returns:
The Obj-C instance.
NSNull* LuaCocoa_CheckNSNull ( struct lua_State *  lua_state,
int  stack_index 
)

Returns NSNull or triggers a Lua error.

Returns NSNull or triggers a Lua error.

Parameters:
lua_stateThe lua_State to operate on.
stack_indexThe index of the stack of the object you want to know about.
Returns:
NSNull.
NSNumber* LuaCocoa_CheckNSNumber ( struct lua_State *  lua_state,
int  stack_index 
)

Returns a NSNumber or triggers a Lua error.

Returns a NSNumber or triggers a Lua error. If the object is already a NSNumber, this will return the pointer. If the object is an integer, float, or boolean, an NSNumber will be constructed and returned.

Parameters:
lua_stateThe lua_State to operate on.
stack_indexThe index of the stack of the object you want to know about.
Returns:
A NSNumber.
NSString* LuaCocoa_CheckNSString ( struct lua_State *  lua_state,
int  stack_index 
)

Returns a NSString or triggers a Lua error.

Returns a NSString or triggers a Lua error. If the object is already a NSString, this will return the pointer. If the object is a string or number, an NSString will be constructed and returned.

Parameters:
lua_stateThe lua_State to operate on.
stack_indexThe index of the stack of the object you want to know about.
Returns:
A NSString.
SEL LuaCocoa_CheckSelector ( struct lua_State *  lua_state,
int  stack_index 
)

Returns a selector or triggers a Lua error.

Returns a selector or triggers a Lua error. Will handle selectors, boxed selectors in NSValues, strings, and NSStrings.

Parameters:
lua_stateThe lua_State to operate on.
stack_indexThe index of the stack of the object you want to know about.
Returns:
A selector.
Warning:
String and NSString are automatically converted to selectors unlike the IsSelector function. Be careful to check for strings/nsstrings separately if you need to distinguish
void* LuaCocoa_CheckStruct ( struct lua_State *  lua_state,
int  stack_index,
const char *  key_name 
)

Returns a pointer to a struct or triggers a Lua error.

Returns a pointer to a struct by the given name at the specified index or triggers a Lua error.

Parameters:
lua_stateThe lua_State to operate on.
stack_indexThe index of the stack of the object you want to know about.
key_nameThe name of the struct.
Returns:
A pointer to the struct.
NSString* LuaCocoa_GetInfoOnFunction ( lua_State *  lua_state,
const char *  function_name,
int *  line_defined,
int *  last_line_defined 
)

Helper function to get debug info on a Lua function.

This is a helper function used to get info about a Lua function. This can be useful for dealing with Lua errors and showing where an error occurred. Assumes function exists. Not expecting to be running in Lua at the moment. Returns autoreleased string containing filename or nil. Returns by reference the line number and last line number of the function.

Parameters:
lua_stateThe lua_State to operate on.
function_nameThe name of the Lua function.
line_definedReturns by reference the line the function is defined on.
last_line_definedReturns by reference the line in the function that an error may occured on.
Returns:
autoreleased string containing filename or nil.
Warning:
This function may change or go away.
const char* LuaCocoa_GetStructName ( struct lua_State *  lua_state,
int  stack_index 
)

Returns the name of the struct.

Returns the name of the struct at the specified index.

Parameters:
lua_stateThe lua_State to operate on.
stack_indexThe index of the stack of the object you want to know about.
Returns:
The name of the struct.
bool LuaCocoa_IsClass ( struct lua_State *  lua_state,
int  stack_index 
)

Returns true if an Obj-C class.

Returns true if the object at the specified index is an Obj-C class.

Parameters:
lua_stateThe lua_State to operate on.
stack_indexThe index of the stack of the object you want to know about.
Returns:
True if an Obj-C class.
bool LuaCocoa_IsInstance ( struct lua_State *  lua_state,
int  stack_index 
)

Returns true if an instance of an Obj-C class.

Returns true if the object at the specified index is an instance of an Obj-C class.

Parameters:
lua_stateThe lua_State to operate on.
stack_indexThe index of the stack of the object you want to know about.
Returns:
True if an Obj-C instance.
bool LuaCocoa_IsNSArray ( struct lua_State *  lua_state,
int  stack_index 
)

Returns true for Lua arrays and NSArrays.

Returns true if the object at the specified index is a Lua array or NSArray. If you are planning to convert a Lua array to an NSArray, it may be faster to just try converting via ToPropertyList and checking the return value instead of running this function since both functions need to do essentially the same thing.

Parameters:
lua_stateThe lua_State to operate on.
stack_indexThe index of the stack of the object you want to know about.
Returns:
True for Lua arrays and NSArrays.
bool LuaCocoa_IsNSDictionary ( struct lua_State *  lua_state,
int  stack_index 
)

Returns true for Lua tables and NSDictionaries.

Returns true if the object at the specified index is a Lua tables or NSDictionary. If you are planning to convert a Lua tables to an NSDictionary, it may be faster to just try converting via ToPropertyList and checking the return value instead of running this function since both functions need to do essentially the same thing.

Parameters:
lua_stateThe lua_State to operate on.
stack_indexThe index of the stack of the object you want to know about.
Returns:
True for Lua tables and NSDictionaries.
bool LuaCocoa_IsNSNull ( struct lua_State *  lua_state,
int  stack_index 
)

Returns true if the object at the specified index is nil or NSNull.

Returns true if the object at the specified index is nil or NSNull.

Parameters:
lua_stateThe lua_State to operate on.
stack_indexThe index of the stack of the object you want to know about.
Returns:
True for nil and NSNull.
bool LuaCocoa_IsNSNumber ( struct lua_State *  lua_state,
int  stack_index 
)

Returns true for integers, floats, booleans, and NSNumbers.

Returns true if the object at the specified index is an integer, float, boolean, or NSNumber.

Parameters:
lua_stateThe lua_State to operate on.
stack_indexThe index of the stack of the object you want to know about.
Returns:
True for integers, floats, booleans, and NSNumbers.
bool LuaCocoa_IsNSString ( struct lua_State *  lua_state,
int  stack_index 
)

Returns true for strings, numbers (which is always convertible to a string), and NSString.

Returns true if the object at the specified index is a strings, number (which is always convertible to a string), or NSString.

Parameters:
lua_stateThe lua_State to operate on.
stack_indexThe index of the stack of the object you want to know about.
Returns:
True for strings, numbers, and NSString.
bool LuaCocoa_IsPropertyList ( struct lua_State *  lua_state,
int  stack_index 
)

Returns true for NSNumber/number, NSNull/nil, NSString/string, NSDictionary, NSArray, or a Lua table.

Returns true for NSNumber/number, NSNull/nil, NSString/string, NSDictionary, NSArray, or a Lua table. If you are planning on converting items, espeicial tables and dictionaries, you might want to just call LuaCocoa_ToPropertyList directly and skip the overhead of doing this check since both methods essentially do the same thing.

Parameters:
lua_stateThe lua_State to operate on.
stack_indexThe index of the stack of the object you want to know about.
Returns:
True for NSNumber/number, NSNull/nil, NSString/string, NSDictionary, NSArray, or a Lua table.
Note:
This method may not handle circular references.
bool LuaCocoa_IsSelector ( struct lua_State *  lua_state,
int  stack_index 
)

Returns true for selectors or selectors boxed in NSValues.

Returns true for selectors or selectors boxed in NSValues.

Parameters:
lua_stateThe lua_State to operate on.
stack_indexThe index of the stack of the object you want to know about.
Returns:
True for selectors or selectors boxed in NSValues.
Warning:
Currently this does not consider strings or NSStrings to be selectors, but the sibling functions do. (Maybe this should change.)
bool LuaCocoa_IsStruct ( struct lua_State *  lua_state,
int  stack_index 
)

Returns true if the object is a struct.

Returns true if the object at the specified index is a struct (as known to the bridge).

Parameters:
lua_stateThe lua_State to operate on.
stack_indexThe index of the stack of the object you want to know about.
Returns:
True if a struct, false if failure.
bool LuaCocoa_IsStructWithName ( struct lua_State *  lua_state,
int  stack_index,
const char *  key_name 
)

Returns true if the object is a struct of the named type you specify.

Returns true if the object at the specified index is a struct of the named type you specify (as known to the bridge).

Parameters:
lua_stateThe lua_State to operate on.
stack_indexThe index of the stack of the object you want to know about.
key_nameThe name of the struct.
Returns:
True if a match, false if failure.
NSString* LuaCocoa_ParseForErrorFilenameAndLineNumber ( NSString *  the_string,
int *  line_number 
)

Helper function to parse a Lua error string and extract the filename and line number.

Helper function to parse a Lua error string and extract the filename and line number.

Parameters:
the_stringThe string containing the Lua error message.
line_numberReturns by reference the line number the error occurred on.
Returns:
The name of the file the error was encountered in.
Warning:
This function may change or go away.
NSString* LuaCocoa_PcallLuaFunction ( lua_State *  lua_state,
lua_CFunction  lua_error_function,
const char *  lua_function_name,
const char *  parameter_signature,
  ... 
)

Convenience method to pcall functions in Lua and allows an error function to be specified.

This convenience method adopts the techniques described in Programming in Lua's call_va function to make calling arbitrary Lua functions a little easier.

Warning:
Parameter signatures are subject to change in future releases to be more consistent with Obj-C. Sorry. FIXME: Unify with Obj-C method signatures. Perhaps call actual LuaCocoa backend for parsing? Adapted from Programming in Lua call_va Example:
 LuaCocoa_PcallLuaFunction(lua_state, error_func, @"OnMouseUp" withSignature:"@@idd>bids@@@@", 
 the_layer, layer_name, button_number, x_pos, y_pos,
 &bool_val, &int_val, &double_val, &str_val, &ns_str_val, &layer_val, &array_val, &dict_val);
In this case, we pass in two Obj-C objects followed by an int and two doubles. The > marker denotes the return types. In this case, we expect the Lua function to return a boolean, int, double, const char* and 4 Obj-C objects. The return objects go through the propertylist conversion, so in particular, Lua tables and arrays get passed back as NSDictionary and NSArray. Notes: Since I pop the stack at the end of the function (so you don't have to worry about balancing), I can't return a char* because it could get deallocated before I am done. So, the easiest answer seems to be to convert to an NSString. So 's' tokens on the return side get copied into NSString, so you must provide that type of variable. Also, passing nil to Lua functions and Lua functions returning nil are not supported well. (nil might work through the property list.) Bugs: error handling isn't quite right. luaL_error isn't right because we haven't pcall'ed yet or have returned from pcall. I don't think error: has all the correct information. I think I need to write a special error handler the case of being outside pcall. TODO: Figure out how to support optional return parameters.
Note:
In addition to Programming in Lua which uses 'b' (boolean) 'd' (double) 'i' (integer) 's' (string) '>' I also add '@' for id, '#' for Class, and 'v' for void*.
Parameters:
lua_stateThe lua_State to operate on.
lua_error_functionThe error function to handle any Lua errors.
lua_function_nameThe name of the Lua function to call.
parameter_signatureA format string describing the parameter types. (See above notes.)
...The list of parameters to go with the format string.
Returns:
A NSString containing an error message if pcall failed, nil otherwise.
NSString* LuaCocoa_PcallLuaFunctionv ( lua_State *  lua_state,
lua_CFunction  lua_error_function,
const char *  lua_function_name,
const char *  parameter_signature,
va_list  vl 
)

Convenience method to pcall functions in Lua and allows an error function to be specified.

This convenience method adopts the techniques described in Programming in Lua's call_va function to make calling arbitrary Lua functions a little easier.

Warning:
Parameter signatures are subject to change in future releases to be more consistent with Obj-C. Sorry. FIXME: Unify with Obj-C method signatures. Perhaps call actual LuaCocoa backend for parsing? Adapted from Programming in Lua call_va Example:
 LuaCocoa_PcallLuaFunctionv(lua_state, error_func, @"OnMouseUp" withSignature:"@@idd>bids@@@@", va_list);
In this case, we pass in two Obj-C objects followed by an int and two doubles. The > marker denotes the return types. In this case, we expect the Lua function to return a boolean, int, double, const char* and 4 Obj-C objects. The return objects go through the propertylist conversion, so in particular, Lua tables and arrays get passed back as NSDictionary and NSArray. Notes: Since I pop the stack at the end of the function (so you don't have to worry about balancing), I can't return a char* because it could get deallocated before I am done. So, the easiest answer seems to be to convert to an NSString. So 's' tokens on the return side get copied into NSString, so you must provide that type of variable. Also, passing nil to Lua functions and Lua functions returning nil are not supported well. (nil might work through the property list.) Bugs: error handling isn't quite right. luaL_error isn't right because we haven't pcall'ed yet or have returned from pcall. I don't think error: has all the correct information. I think I need to write a special error handler the case of being outside pcall. TODO: Figure out how to support optional return parameters.
Note:
In addition to Programming in Lua which uses 'b' (boolean) 'd' (double) 'i' (integer) 's' (string) '>' I also add '@' for id, '#' for Class, and 'v' for void*.
Parameters:
lua_stateThe lua_State to operate on.
lua_error_functionThe error function to handle any Lua errors.
lua_function_nameThe name of the Lua function to call.
parameter_signatureA format string describing the parameter types. (See above notes.)
vlThe list of parameters to go with the format string.
Returns:
A NSString containing an error message if pcall failed, nil otherwise.
void LuaCocoa_PrependToCSearchPath ( struct lua_State *  lua_state,
const char *  search_path 
)

Prepends a new path the Lua/C package search path.

Modifies the package.cpath to append the specified string. Should be in proper lua format: e.g. /Users/ewing/Library/Application Support/LuaCocoa/PlugIns/?.so This means you must explicitly include the ?.so (or whatever file extensions you use.)

Parameters:
lua_stateThe lua_State to operate on.
search_pathThe path to prepend.
void LuaCocoa_PrependToLuaSearchPath ( struct lua_State *  lua_state,
const char *  search_path 
)

Prepends a new path the Lua package search path.

Modifies the package.path to append the specified string. Should be in proper lua format: e.g. /Users/ewing/Source/HG/LuaCocoa/Xcode/build/Debug/LuaCocoa.framework/Resources/?.lua This means you must explicitly include the ?.lua (or whatever file extensions you use.)

Parameters:
lua_stateThe lua_State to operate on.
search_pathThe path to prepend.
void LuaCocoa_PushClass ( struct lua_State *  lua_state,
Class  the_class 
)

Pushes an Obj-C class.

Pushes an Obj-C class into Lua.

Parameters:
lua_stateThe lua_State to operate on.
the_classThe class to push.
void LuaCocoa_PushInstance ( struct lua_State *  lua_state,
id  the_object 
)

Pushes an Obj-C instance.

Pushes an Obj-C instance into Lua.

Parameters:
lua_stateThe lua_State to operate on.
the_objectThe object to push.
void LuaCocoa_PushSelector ( struct lua_State *  lua_state,
SEL  the_selector 
)

Pushes a selector into Lua.

On failure, nil is pushed.

Parameters:
lua_stateThe lua_State to operate on.
the_selectorThe selector push.
bool LuaCocoa_PushStruct ( struct lua_State *  lua_state,
void *  the_struct,
const char *  key_name 
)

Pushes a copy of the struct passed in onto the stack.

Pushes a copy of the struct passed in onto the stack. If the metatable for the struct type cannot be found, the function will fail and nothing will be pushed.

Parameters:
lua_stateThe lua_State to operate on.
the_structA pointer to the struct to push
key_nameThe name of the struct.
Returns:
False if there is a failure.
void LuaCocoa_PushUnboxedNSArray ( struct lua_State *  lua_state,
NSArray *  the_array 
)

Converts a NSArray to a Lua array (table) and pushes it on the stack.

Converts a NSArray to a Lua array (table) and pushes it on the stack. Elements contained in the NSArray will also (recursively) be converted to equivalent Lua types.

Parameters:
lua_stateThe lua_State to operate on.
the_arrayThe NSArray to push.
void LuaCocoa_PushUnboxedNSDictionary ( struct lua_State *  lua_state,
NSDictionary *  the_dictionary 
)

Converts a NSDictionary to a Lua table and pushes it on the stack.

Elements contained in the NSDictionary will also (recursively) be converted to equivalent Lua types. Converts a NSDictionary to a Lua table and pushes it on the stack. Converts a NSDictionary to a Lua table and pushes it on the stack. Elements contained in the NSDictionary will also (recursively) be converted to equivalent Lua types.

Parameters:
lua_stateThe lua_State to operate on.
the_dictionaryThe NSDictionary to push.
void LuaCocoa_PushUnboxedNSNumber ( struct lua_State *  lua_state,
NSNumber *  the_number 
)

Pushes a Lua number converted from an NSNumber onto the stack (instead of pushing the NSObject through the bridge).

Note that if the NSNumber is a boolean, it will push a Lua boolean instead. On failure, nil is pushed.

Parameters:
lua_stateThe lua_State to operate on.
the_numberThe NSNumber to copy/push.
void LuaCocoa_PushUnboxedNSString ( struct lua_State *  lua_state,
NSString *  the_string 
)

Pushes a Lua string converted from an NSString onto the stack (instead of pushing the NSObject through the bridge).

On failure, nil is pushed.

Parameters:
lua_stateThe lua_State to operate on.
the_stringThe NSString to copy/push.
void LuaCocoa_PushUnboxedPropertyList ( struct lua_State *  lua_state,
id  the_object 
)

Converts Cocoa types to Lua types and pushes on the stack.

Converts the following Cocoa containers to their Lua equivalent types: NSNumber => number, NSNull => nil, NSString => string, NSDictionary => table, NSArray => table. Elements contained in NSDictionaries and NSArrays will also (recursively) be converted to their Lua equivalent types. This method will recursively convert items in arrays and dictionaries.

Parameters:
lua_stateThe lua_State to operate on.
the_objectThe Cocoa object to convert to Lua and push.
Note:
This method may not handle circular references.
Class LuaCocoa_ToClass ( struct lua_State *  lua_state,
int  stack_index 
)

Returns an Obj-C class.

Returns an Obj-C class at the specified index or nil.

Parameters:
lua_stateThe lua_State to operate on.
stack_indexThe index of the stack of the object you want to know about.
Returns:
The Obj-C class or nil.
id LuaCocoa_ToInstance ( struct lua_State *  lua_state,
int  stack_index 
)

Returns an Obj-C instance.

Returns an Obj-C instance at the specified index or nil.

Parameters:
lua_stateThe lua_State to operate on.
stack_indexThe index of the stack of the object you want to know about.
Returns:
The Obj-C instance or nil.
NSNull* LuaCocoa_ToNSNull ( struct lua_State *  lua_state,
int  stack_index 
)

Returns NSNull.

Returns NSNull at the specified index or nil.

Parameters:
lua_stateThe lua_State to operate on.
stack_indexThe index of the stack of the object you want to know about.
Returns:
NSNull.
NSNumber* LuaCocoa_ToNSNumber ( struct lua_State *  lua_state,
int  stack_index 
)

Returns a NSNumber.

Returns a NSNumber at the specified index or nil. If the object is already a NSNumber, this will return the pointer. If the object is an integer, float, or boolean, an NSNumber will be constructed and returned.

Parameters:
lua_stateThe lua_State to operate on.
stack_indexThe index of the stack of the object you want to know about.
Returns:
A NSNumber.
NSString* LuaCocoa_ToNSString ( struct lua_State *  lua_state,
int  stack_index 
)

Returns a NSString.

Returns a NSString at the specified index or nil. If the object is already a NSString, this will return the pointer. If the object is a string or number, an NSString will be constructed and returned.

Parameters:
lua_stateThe lua_State to operate on.
stack_indexThe index of the stack of the object you want to know about.
Returns:
A NSString.
id LuaCocoa_ToPropertyList ( struct lua_State *  lua_state,
int  stack_index 
)

Converts Lua types to Cocoa types.

Returns or converts the element at the stack index to one of the appropriate Cocoa containers: NSNumber => number, NSNull => nil, NSString => string, NSDictionary => table, NSArray => table. In NSDictionaries and NSArrays, NSNull might be substituted as placeholders for Lua types that can't be boxed/converted to Cocoa equivalents. This method will recursively convert items in arrays and dictionaries.

Parameters:
lua_stateThe lua_State to operate on.
stack_indexThe index of the stack of the object you want to know about.
Returns:
Returns the Cocoa equivalent container.
Note:
This method may not handle circular references.
SEL LuaCocoa_ToSelector ( struct lua_State *  lua_state,
int  stack_index 
)

Returns a selector.

Returns a selector at the specified index or nil.

Parameters:
lua_stateThe lua_State to operate on.
stack_indexThe index of the stack of the object you want to know about.
Returns:
A selector.
Warning:
String and NSString are automatically converted to selectors unlike the IsSelector function. Be careful to check for strings/nsstrings separately if you need to distinguish
__strong const char* LuaCocoa_ToString ( struct lua_State *  lua_state,
int  stack_index 
)

If a NSString, returns C-string, or if C-string, returns C-string.

Returns a C string. Returns a C string at the specified index or nil. If the object is a NSString, the implementation tends to call UTF8String/

Parameters:
lua_stateThe lua_State to operate on.
stack_indexThe index of the stack of the object you want to know about.
Returns:
C string.