Browse files

pre-fix

  • Loading branch information...
1 parent e74ad99 commit 9e1e21c9f798beefd302ff09fdf26383e7340f53 @probablycorey committed Nov 10, 2009
View
4 FAQ
@@ -0,0 +1,4 @@
+How to handle a method that takes a pointer to NSError
+
+local error = toobjc(nil)
+toobjc("HILL"):writeToFile_atomically_encoding_error(path, false, NSUTF8StringEncoding, error)
View
2 examples/WaxTests/data/scripts/init.lua
@@ -8,4 +8,4 @@ require "protocolTest"
require "structTest"
require "gcTest"
-spec:report(true)
+
View
68 lib/build-scripts/luac.lua
@@ -0,0 +1,68 @@
+#!/usr/bin/env lua
+
+-- usage: lua luac.lua base_dir [file.lua]* [-L [module.lua]*]
+--
+-- base_dir: The root for all the lua files. So folder modules can be used
+--
+-- creates a precompiled chunk that preloads all modules listed after
+-- -L and then runs all programs listed before -L.
+--
+-- assumptions:
+-- file xxx.lua contains module xxx
+-- '/' is the directory separator (could have used package.config)
+-- int and size_t take 4 bytes (could have read sizes from header)
+-- does not honor package.path
+--
+-- Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br>
+-- Tue Aug 5 22:57:33 BRT 2008
+-- This code is hereby placed in the public domain.
+
+local MARK = "////////"
+local NAME = "luac"
+
+local OUTPUT = table.remove(arg, 1)
+local BASE_DIR = table.remove(arg, 1)
+NAME = "=("..NAME..")"
+
+local argCount = #arg
+local executableIndex = n
+local b
+
+for i = 1, argCount do
+ if arg[i] == "-L" then executableIndex = i - 1 break end
+end
+
+if executableIndex + 2 <= argCount then b = "local t=package.preload;\n" else b = "local t;\n" end
+
+for i = executableIndex + 2, argCount do
+ local requireString = string.gsub(arg[i], string.gsub(BASE_DIR, "(%W)", "%%%1"), "")
+ requireString = string.gsub(requireString,"^[\./]*(.-)\.lua$", "%1")
+ requireString = string.gsub(requireString, "/", ".")
+ requireString = string.gsub(requireString, ".init$", "") -- if it is an init file within a directory... ignore it!
+
+ b = b.."t['"..requireString.."']=function()end;\n"
+ arg[i]=string.sub(string.dump(assert(loadfile(arg[i]))), 13) -- string.sub Removes header from file
+end
+b = b.."t='"..MARK.."';\n"
+
+for i = 1, executableIndex do
+ b = b.."(function()end)();\n"
+ arg[i]=string.sub(string.dump(assert(loadfile(arg[i]))), 13) -- string.sub Removes header from file
+end
+
+print(b)
+
+b = string.dump(assert(loadstring(b, NAME)))
+local x, y = string.find(b, MARK)
+
+b = string.sub(b, 1, x - 6).."\0"..string.sub(b, y + 2, y + 5) -- WTF does this do?
+
+f = assert(io.open(OUTPUT, "wb"))
+
+assert(f:write(b))
+
+for i = executableIndex + 2, argCount do
+ assert(f:write(arg[i]))
+end
+
+
View
2 lib/extensions/HTTPotluck/HTTPotluck.m
@@ -92,7 +92,7 @@ static int request(lua_State *L) {
NSRunLoop* runLoop = [NSRunLoop currentRunLoop];
while (!connection.finished) {
- [runLoop runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
+ [runLoop runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
}
return 3;
View
22 lib/wax-scripts/enums.lua
@@ -196,3 +196,25 @@ UITextBorderStyleNone = 0
UITextBorderStyleLine = 1
UITextBorderStyleBezel = 2
UITextBorderStyleRoundedRect = 3
+
+
+-- UITableViewScrollPosition
+UITableViewScrollPositionNone = 0
+UITableViewScrollPositionTop = 1
+UITableViewScrollPositionMiddle = 2
+UITableViewScrollPositionBottom = 3
+
+-- UIKeyboardAppearance
+UIKeyboardAppearanceDefault = 0
+UIKeyboardAppearanceAlert = 1
+
+-- UITextFieldViewMode
+UITextFieldViewModeNever = 0
+UITextFieldViewModeWhileEditing = 1
+UITextFieldViewModeUnlessEditing = 2
+UITextFieldViewModeAlways = 3
+
+-- UITextAutocorrectionType
+UITextAutocorrectionTypeDefault = 0
+UITextAutocorrectionTypeNo = 1
+UITextAutocorrectionTypeYes = 2
View
6 lib/wax-scripts/ext/table.lua
@@ -58,13 +58,13 @@ end
function table.find(t, func)
for k, v in pairs(t) do
- if func(v) then return k, v end
+ if func(v) then return k, v end
end
return nil
end
-function table.findAll(t, func)
+function table.select(t, func)
local matches = {}
for k, v in pairs(t) do
if func(v) then table.insert(matches, v) end
@@ -103,4 +103,4 @@ function table.tostring(t, indent)
end
return table.concat(output)
-end
+end
View
2 lib/wax-scripts/init.lua
@@ -10,4 +10,4 @@ require "wax.cocoaNamespace"
cocoaNamespace("UI")
cocoaNamespace("NS")
cocoaNamespace("MK")
-cocoaNamespace("MF")
+cocoaNamespace("MF")
View
6 lib/wax-scripts/luaspec/luaspec.lua
@@ -88,8 +88,6 @@ end
function spec:add_pending_spec(context_name, spec_name, pending_description)
end
---
-
-- create tables to support pending specifications
local pending = {}
@@ -115,14 +113,14 @@ setmetatable(pending, pending)
-- define matchers
-matchers = {
+matchers = {
should_be = function(value, expected)
if value ~= expected then
return false, "expecting "..tostring(expected)..", not ".. tostring(value)
end
return true
end;
-
+
should_not_be = function(value, expected)
if value == expected then
return false, "should not be "..tostring(value)
View
6 lib/wax.m
@@ -18,7 +18,7 @@
lua_State *wax_currentLuaState() {
static lua_State *L;
- if (!L) L = lua_open();
+ if (!L) L = lua_open();
return L;
}
@@ -35,8 +35,8 @@ void wax_startWithExtensions(lua_CFunction func, ...) {
lua_State *L = wax_currentLuaState();
- NSArray *args = [[NSProcessInfo processInfo] arguments];
- if ([args containsObject:@"test"]) {
+ NSDictionary *env = [[NSProcessInfo processInfo] environment];
+ if ([[env objectForKey:@"WAX_TEST"] isEqual:@"1"]) { // If there is a WAX_TEST env, then run the tests!
mainFile = "scripts/tests/init.lua";
}
else {
View
7 lib/wax_helpers.h
@@ -63,10 +63,12 @@
#define END_STACK_MODIFY(L, i) while(lua_gettop((L)) > (__startStackIndex + (i))) lua_remove((L), __startStackIndex + 1);
#ifndef LOG_FLAGS
- #define LOG_FLAGS 0
+ #define LOG_FLAGS (LOG_GC | LOG_FATAL | LOG_DEBUG)
#endif
#define LOG_GC 1
+#define LOG_DEBUG 2
+#define LOG_FATAL 4
// This struct seem unnessessary
typedef struct _wax_selectors {
@@ -97,5 +99,8 @@ const char *wax_removeProtocolEncodings(const char *type_descriptions);
int wax_sizeOfTypeDescription(const char *full_type_description);
int wax_simplifyTypeDescription(const char *in, char *out);
+void wax_copyTable(lua_State *from, lua_State *to, int index);
+void wax_copyObject(lua_State *from, lua_State *to, int index);
+
int wax_errorFunction(lua_State *L);
int wax_pcall(lua_State *L, int argumentCount, int returnCount);
View
59 lib/wax_helpers.m
@@ -286,10 +286,16 @@ void wax_fromInstance(lua_State *L, id instance) {
break;
case WAX_TYPE_SELECTOR:
- *outsize = sizeof(SEL);
- value = calloc(sizeof(SEL), 1);
- const char *selectorName = luaL_checkstring(L, stackIndex);
- *((SEL *)value) = sel_getUid(selectorName);
+ if (lua_isnil(L, stackIndex)) { // If no slector is passed it, just use an empty string
+ lua_pushstring(L, "");
+ lua_replace(L, stackIndex);
+ }
+
+ *outsize = sizeof(SEL);
+ value = calloc(sizeof(SEL), 1);
+ const char *selectorName = luaL_checkstring(L, stackIndex);
+ *((SEL *)value) = sel_getUid(selectorName);
+
break;
case WAX_TYPE_CLASS:
@@ -722,6 +728,51 @@ int wax_simplifyTypeDescription(const char *in, char *out) {
return out_index;
}
+void wax_copyTable(lua_State *from, lua_State *to, int index) {
+ lua_newtable(to);
+
+ lua_pushnil(from); // first key
+
+ while (lua_next(from, index) != 0) {
+ wax_copyObject(from, to, -2); // copy the key
+ wax_copyObject(from, to, -1); // copy the value
+
+ lua_rawset(to, -3);
+
+ lua_pop(from, 1); // remove 'value'; keeps 'key' for next iteration
+ }
+
+ int i = 0;
+ i++;
+ i = 1 + i;
+}
+
+void wax_copyObject(lua_State *from, lua_State *to, int index) {
+ // make index positive
+ if (index < 0) index = lua_gettop(from) + 1 + index;
+
+ switch (lua_type(from, index)) {
+ case LUA_TNIL:
+ lua_pushnil(to);
+ break;
+ case LUA_TNUMBER:
+ lua_pushnumber(to, lua_tonumber(from, index));
+ break;
+ case LUA_TBOOLEAN:
+ lua_pushboolean(to, lua_toboolean(from, index));
+ break;
+ case LUA_TSTRING:
+ lua_pushstring(to, lua_tostring(from, index));
+ break;
+ case LUA_TTABLE:
+ wax_copyTable(from, to, index);
+ break;
+ default:
+ luaL_error(from, "Can not copy object of type '%s'", lua_typename(from, index));
+ break;
+ }
+}
+
int wax_errorFunction(lua_State *L) {
lua_getfield(L, LUA_GLOBALSINDEX, "debug");
if (!lua_istable(L, -1)) {
View
6 lib/wax_instance.m
@@ -52,11 +52,11 @@ int luaopen_wax_instance(lua_State *L) {
wax_instance_pushUserdata(L, instance);
if (lua_isnil(L, -1)) {
- wax_log(LOG_GC, @"Creating object for %@(%p)", instance, instance);
+ wax_log(LOG_GC, @"Creating object for %@(%p)", [instance class], instance);
lua_pop(L, 1); // pop nil stack
}
else {
- wax_log(LOG_GC, @"Found existing userdata object for %@(%p)", instance, instance);
+ wax_log(LOG_GC, @"Found existing userdata object for %@(%p)", [instance class], instance);
return lua_touserdata(L, -1);
}
@@ -67,7 +67,7 @@ int luaopen_wax_instance(lua_State *L) {
instanceUserdata->isSuper = NO;
if (!isClass) {
- wax_log(LOG_GC, @"Retaining object for %@(%p)", instance, instance);
+ wax_log(LOG_GC, @"Retaining object for %@(%p)", [instance class], instance);
[instanceUserdata->instance retain];
}

0 comments on commit 9e1e21c

Please sign in to comment.