• Main Page
  • Classes
  • Files
  • File List
  • File Members

LuaCocoa.h

Go to the documentation of this file.
00001 /*
00002  LuaCocoa
00003  Copyright (C) 2009-2011 PlayControl Software. 
00004  Eric Wing <ewing . public @ playcontrol.net>
00005  
00006  Permission is hereby granted, free of charge, to any person obtaining a copy
00007  of this software and associated documentation files (the "Software"), to deal
00008  in the Software without restriction, including without limitation the rights
00009  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00010  copies of the Software, and to permit persons to whom the Software is
00011  furnished to do so, subject to the following conditions:
00012  
00013  The above copyright notice and this permission notice shall be included in
00014  all copies or substantial portions of the Software.
00015  
00016  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00019  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00020  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00021  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00022  THE SOFTWARE.
00023  
00024  */
00025 
00026 #ifndef LUA_COCOA_H
00027 #define LUA_COCOA_H
00028 
00029 
00030 #ifndef DOXYGEN_SHOULD_IGNORE_THIS
00031 
00033 /* Note: For Doxygen to produce clean output, you should set the 
00034  * PREDEFINED option to remove ALMIXER_DECLSPEC, ALMIXER_CALL, and
00035  * the DOXYGEN_SHOULD_IGNORE_THIS blocks.
00036  * PREDEFINED = DOXYGEN_SHOULD_IGNORE_THIS=1 ALMIXER_DECLSPEC= ALMIXER_CALL=
00037  */
00038 
00039 #if defined(__cplusplus)
00040     #define LUACOCOA_EXTERN extern "C"
00041 #else
00042     #define LUACOCOA_EXTERN extern
00043 #endif
00044 
00045 #if TARGET_OS_WIN32
00046 
00047     #if defined(NSBUILDINGLUACOCOA)
00048         #define LUACOCOA_EXPORT __declspec(dllexport)
00049     #else
00050         #define LUACOCOA_EXPORT __declspec(dllimport)
00051     #endif
00052 
00053     #define LUACOCOA_IMPORT __declspec(dllimport)
00054 
00055 #else
00056     #if defined(__GNUC__) && __GNUC__ >= 4 && defined(NSBUILDINGLUACOCOA)
00057         #define LUACOCOA_EXPORT __attribute__ ((visibility("default")))
00058     #else
00059         #define LUACOCOA_EXPORT
00060     #endif
00061     
00062     #define LUACOCOA_IMPORT
00063 #endif
00064 
00066 #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
00067 
00068 
00069 
00070 #include <stdarg.h> /* va_list */
00071 #include <stdbool.h>
00072 
00073 #ifdef LUACOCOA_DONT_USE_BUNDLED_LUA_HEADERS
00074     #include "lua.h"
00075     #include "lualib.h"
00076     #include "lauxlib.h"
00077 #else
00078     /* Since I compiled Lua with C-linkage for LuaCocoa, C++ users need the header guards since Lua doesn't
00079      * specify them in their main headers.
00080      */
00081     #ifdef __cplusplus
00082     extern "C" {
00083     #endif
00084         #include <LuaCocoa/lua.h>
00085         #include <LuaCocoa/lualib.h>
00086         #include <LuaCocoa/lauxlib.h>
00087     #ifdef __cplusplus
00088     }
00089     #endif
00090 #endif /* end LUACOCOA_DONT_USE_BUNDLED_LUA_HEADERS */
00091 /* Hide Obj-C stuff for people writing pure C (or C++) programs that just want access to the LuaCocoa C APIs */
00092 #ifdef __OBJC__ 
00093 #import <Foundation/Foundation.h>
00094 
00095 // Forward declaration so I don't need to #include "lua.h" here. (I don't have to worry about the search path of Lua for the public header.)
00096 // But I have to use the formal "struct" version of the name instead of the typedef, i.e. "struct lua_State" instead of just "lua_State"
00097 struct lua_State;
00098 
00099 // Not sure if I want to make part of the API
00100 /*
00101 @protocol LuaCocoaErrorDelegate <NSObject>
00102 @optional
00103 - (void) error:(NSString*)error_string luaState:(lua_State*)lua_state functionName:(NSString*)function_name fileName:(NSString*)file_name lineNumber:(NSInteger)line_number;
00104 @end
00105 */
00106 
00114 LUACOCOA_EXPORT @interface LuaCocoa : NSObject
00115 {
00116 @private
00117     struct lua_State* luaState;
00118     bool ownsLuaState;
00119     NSMutableDictionary* frameworksLoaded;
00120     bool skipDLopen; // in case you are using with other language bridges
00121     bool disableImportFromLua; // consider for sandboxing
00122 
00123     // Not sure if I want to make part of the API
00124 //  lua_CFunction luaErrorFunction;
00125 //  id<LuaCocoaErrorDelegate> errorDelegate;
00126 
00127 }
00133 @property(assign, readonly) struct lua_State* luaState;
00134 @property(assign) bool skipDLopen;
00135 @property(assign) bool disableImportFromLua;
00136 
00137 // Not sure if I want to make part of the API
00138 //@property(assign) lua_CFunction luaErrorFunction;
00139 //@property(assign) id<LuaCocoaErrorDelegate> errorDelegate;
00140 
00146 - (id) init;
00147 
00155 - (id) initWithLuaState:(struct lua_State*)lua_state assumeOwnership:(bool)should_assume_ownership;
00156 
00157 // Might be moved to private API
00158 - (bool) loadFrameworkWithBaseName:(NSString*)base_name hintPath:(NSString*)hint_path searchHintPathFirst:(bool)search_hint_path_first skipDLopen:(bool)skip_dl_open;
00159 
00160 // Might be moved to private API
00161 - (bool) isFrameworkLoaded:(NSString*)base_name;
00162 
00175 - (void) collectExhaustivelyWaitUntilDone:(bool)should_wait_until_done;
00176 
00185 + (void) collectExhaustivelyWaitUntilDone:(bool)should_wait_until_done;
00186 
00221 - (NSString*) pcallLuaFunction:(const char*)lua_function_name withSignature:(const char*)parameter_signature, ...;
00257 - (NSString*) pcallLuaFunction:(const char*)lua_function_name errorFunction:(lua_CFunction)error_function withSignature:(const char*)parameter_signature, ...;
00258 // Not sure if I want to make an API or not
00259 //- (void) error:(const char *)fmt, ...;
00260 
00261 @end
00262 
00263 
00264 //LUACOCOA_EXTERN LUACOCOA_EXPORT NSString* const kLuaCocoaErrorDomain /* = @"kLuaCocoaErrorDomain" */;
00265 
00273 LUACOCOA_EXTERN LUACOCOA_EXPORT bool LuaCocoa_IsInstance(struct lua_State* lua_state, int stack_index);
00281 LUACOCOA_EXTERN LUACOCOA_EXPORT id LuaCocoa_CheckInstance(struct lua_State* lua_state, int stack_index);
00289 LUACOCOA_EXTERN LUACOCOA_EXPORT id LuaCocoa_ToInstance(struct lua_State* lua_state, int stack_index);
00296 LUACOCOA_EXTERN LUACOCOA_EXPORT void LuaCocoa_PushInstance(struct lua_State* lua_state, id the_object);
00297 
00305 LUACOCOA_EXTERN LUACOCOA_EXPORT bool LuaCocoa_IsClass(struct lua_State* lua_state, int stack_index);
00313 LUACOCOA_EXTERN LUACOCOA_EXPORT Class LuaCocoa_CheckClass(struct lua_State* lua_state, int stack_index);
00321 LUACOCOA_EXTERN LUACOCOA_EXPORT Class LuaCocoa_ToClass(struct lua_State* lua_state, int stack_index);
00328 LUACOCOA_EXTERN LUACOCOA_EXPORT void LuaCocoa_PushClass(struct lua_State* lua_state, Class the_class);
00329 
00337 LUACOCOA_EXTERN LUACOCOA_EXPORT bool LuaCocoa_IsNSNumber(struct lua_State* lua_state, int stack_index);
00346 LUACOCOA_EXTERN LUACOCOA_EXPORT NSNumber* LuaCocoa_CheckNSNumber(struct lua_State* lua_state, int stack_index);
00356 LUACOCOA_EXTERN LUACOCOA_EXPORT NSNumber* LuaCocoa_ToNSNumber(struct lua_State* lua_state, int stack_index);
00364 LUACOCOA_EXTERN LUACOCOA_EXPORT void LuaCocoa_PushUnboxedNSNumber(struct lua_State* lua_state, NSNumber* the_number);
00365 
00373 LUACOCOA_EXTERN LUACOCOA_EXPORT bool LuaCocoa_IsNSNull(struct lua_State* lua_state, int stack_index);
00381 LUACOCOA_EXTERN LUACOCOA_EXPORT NSNull* LuaCocoa_CheckNSNull(struct lua_State* lua_state, int stack_index);
00389 LUACOCOA_EXTERN LUACOCOA_EXPORT NSNull* LuaCocoa_ToNSNull(struct lua_State* lua_state, int stack_index);
00390 
00398 LUACOCOA_EXTERN LUACOCOA_EXPORT bool LuaCocoa_IsNSString(struct lua_State* lua_state, int stack_index);
00407 LUACOCOA_EXTERN LUACOCOA_EXPORT NSString* LuaCocoa_CheckNSString(struct lua_State* lua_state, int stack_index);
00417 LUACOCOA_EXTERN LUACOCOA_EXPORT NSString* LuaCocoa_ToNSString(struct lua_State* lua_state, int stack_index);
00418 
00425 LUACOCOA_EXTERN LUACOCOA_EXPORT void LuaCocoa_PushUnboxedNSString(struct lua_State* lua_state, NSString* the_string);
00437 LUACOCOA_EXTERN LUACOCOA_EXPORT __strong const char* LuaCocoa_ToString(struct lua_State* lua_state, int stack_index);
00438 
00449 LUACOCOA_EXTERN LUACOCOA_EXPORT bool LuaCocoa_IsNSArray(struct lua_State* lua_state, int stack_index);
00457 LUACOCOA_EXTERN LUACOCOA_EXPORT void LuaCocoa_PushUnboxedNSArray(struct lua_State* lua_state, NSArray* the_array);
00458 
00459 
00470 LUACOCOA_EXTERN LUACOCOA_EXPORT bool LuaCocoa_IsNSDictionary(struct lua_State* lua_state, int stack_index);
00482 LUACOCOA_EXTERN LUACOCOA_EXPORT void LuaCocoa_PushUnboxedNSDictionary(struct lua_State* lua_state, NSDictionary* the_dictionary);
00483 
00495 LUACOCOA_EXTERN LUACOCOA_EXPORT bool LuaCocoa_IsPropertyList(struct lua_State* lua_state, int stack_index);
00508 LUACOCOA_EXTERN LUACOCOA_EXPORT id LuaCocoa_ToPropertyList(struct lua_State* lua_state, int stack_index);
00509 
00520 LUACOCOA_EXTERN LUACOCOA_EXPORT void LuaCocoa_PushUnboxedPropertyList(struct lua_State* lua_state, id the_object);
00521 
00522 
00523 // Warning: will convert strings and nsstrings and NSValue's with correct encoding to selectors
00524 // Becareful to check for strings/nsstrings separately if you need to distinguish
00533 LUACOCOA_EXTERN LUACOCOA_EXPORT bool LuaCocoa_IsSelector(struct lua_State* lua_state, int stack_index);
00542 LUACOCOA_EXTERN LUACOCOA_EXPORT SEL LuaCocoa_CheckSelector(struct lua_State* lua_state, int stack_index);
00551 LUACOCOA_EXTERN LUACOCOA_EXPORT SEL LuaCocoa_ToSelector(struct lua_State* lua_state, int stack_index);
00558 LUACOCOA_EXTERN LUACOCOA_EXPORT void LuaCocoa_PushSelector(struct lua_State* lua_state, SEL the_selector);
00559 
00574 LUACOCOA_EXTERN LUACOCOA_EXPORT NSString* LuaCocoa_GetInfoOnFunction(lua_State* lua_state, const char* function_name, int* line_defined, int* last_line_defined);
00575 
00584 LUACOCOA_EXTERN LUACOCOA_EXPORT NSString* LuaCocoa_ParseForErrorFilenameAndLineNumber(NSString* the_string, int* line_number);
00585 
00586 // Warning: Parameter signatures are subject to change in future releases to be more consistent with Obj-C. Sorry.
00623 LUACOCOA_EXTERN LUACOCOA_EXPORT NSString* LuaCocoa_PcallLuaFunction(lua_State* lua_state, lua_CFunction lua_error_function, const char* lua_function_name, const char* parameter_signature, ...);
00658 LUACOCOA_EXTERN LUACOCOA_EXPORT NSString* LuaCocoa_PcallLuaFunctionv(lua_State* lua_state, lua_CFunction lua_error_function, const char* lua_function_name, const char* parameter_signature, va_list vl);
00659 
00660 
00661 #endif /* __OBJC__ */
00662 
00671 LUACOCOA_EXTERN LUACOCOA_EXPORT void LuaCocoa_PrependToLuaSearchPath(struct lua_State* lua_state, const char* search_path);
00672 
00681 LUACOCOA_EXTERN LUACOCOA_EXPORT void LuaCocoa_AppendToLuaSearchPath(struct lua_State* lua_state, const char* search_path);
00682 
00691 LUACOCOA_EXTERN LUACOCOA_EXPORT void LuaCocoa_PrependToCSearchPath(struct lua_State* lua_state, const char* search_path);
00692 
00701 LUACOCOA_EXTERN LUACOCOA_EXPORT void LuaCocoa_AppendToCSearchPath(struct lua_State* lua_state, const char* search_path);
00702 
00703 
00704 // These struct APIs may be subject to change. I'm unhappy with the keyname vs. structname issues.
00705 // These functions are mostly untested. Please report bugs/problems/API defects.
00713 LUACOCOA_EXTERN LUACOCOA_EXPORT bool LuaCocoa_IsStruct(struct lua_State* lua_state, int stack_index);
00722 LUACOCOA_EXTERN LUACOCOA_EXPORT bool LuaCocoa_IsStructWithName(struct lua_State* lua_state, int stack_index, const char* key_name);
00730 LUACOCOA_EXTERN LUACOCOA_EXPORT const char* LuaCocoa_GetStructName(struct lua_State* lua_state, int stack_index);
00739 LUACOCOA_EXTERN LUACOCOA_EXPORT void* LuaCocoa_CheckStruct(struct lua_State* lua_state, int stack_index, const char* key_name);
00749 LUACOCOA_EXTERN LUACOCOA_EXPORT bool LuaCocoa_PushStruct(struct lua_State* lua_state, void* the_struct, const char* key_name);
00750 
00751 #endif /* LUA_COCOA_H */

Generated on Sat Aug 6 2011 12:51:58 for LuaCocoa by  doxygen 1.7.2