Browse files

making possible to end and start again wax session during single appl…

…ication runtime
  • Loading branch information...
1 parent 95c2a41 commit 53061f105a1d9363fba6bc5c4a457c7d3300843a @zbyhoo zbyhoo committed Apr 6, 2012
Showing with 18 additions and 8 deletions.
  1. +7 −3 lib/wax.m
  2. +1 −4 lib/wax_class.m
  3. +1 −0 lib/wax_gc.h
  4. +9 −1 lib/wax_gc.m
View
10 lib/wax.m
@@ -29,11 +29,13 @@
static int exitApp(lua_State *L);
static int objcDebug(lua_State *L);
+static lua_State *currentL;
lua_State *wax_currentLuaState() {
- static lua_State *L;
- if (!L) L = lua_open();
- return L;
+ if (!currentL)
+ currentL = lua_open();
+
+ return currentL;
}
void uncaughtExceptionHandler(NSException *e) {
@@ -152,7 +154,9 @@ void wax_startWithServer() {
}
void wax_end() {
+ [wax_gc stop];
lua_close(wax_currentLuaState());
+ currentL = 0;
}
static void addGlobals(lua_State *L) {
View
5 lib/wax_class.m
@@ -73,10 +73,7 @@ static int __call(lua_State *L) {
const char *className = luaL_checkstring(L, 2);
Class klass = objc_getClass(className);
- if (klass) { // Class should not already exist!
- luaL_error(L, "Trying to create a class named '%s', but one already exists.", className);
- }
- else {
+ if (!klass) {
Class superClass;
if (lua_isuserdata(L, 3)) {
wax_instance_userdata *instanceUserdata = (wax_instance_userdata *)luaL_checkudata(L, 3, WAX_INSTANCE_METATABLE_NAME);
View
1 lib/wax_gc.h
@@ -14,6 +14,7 @@
}
+ (void)start;
++ (void)stop;
+ (void)cleanupUnusedObject;
@end
View
10 lib/wax_gc.m
@@ -19,8 +19,16 @@
@implementation wax_gc
+static NSTimer* timer = nil;
+
+ (void)start {
- [NSTimer scheduledTimerWithTimeInterval:WAX_GC_TIMEOUT target:self selector:@selector(cleanupUnusedObject) userInfo:nil repeats:YES];
+ [timer invalidate];
+ timer = [NSTimer scheduledTimerWithTimeInterval:WAX_GC_TIMEOUT target:self selector:@selector(cleanupUnusedObject) userInfo:nil repeats:YES];
+}
+
++ (void)stop {
+ [timer invalidate];
+ timer = nil;
}
+ (void)cleanupUnusedObject {

0 comments on commit 53061f1

Please sign in to comment.