how using NSPredicate (many args) in wax

75 views
Skip to first unread message

Dave Wang

unread,
Mar 7, 2013, 2:07:59 AM3/7/13
to ipho...@googlegroups.com
hi,anybody!
     Using NSPredicate in lua that is not working!
      eq:
Objective-c Code 
     NSPredicate *p = [NSPredicate predicateWithFormat:@"SELF MATCHES %@ ",@"[0-9]{0,25}+$"];

    if ( [p evaluateWithObject:@"121"]) {

         NSLog(@"p");

    }else{

    NSLog(@"not p");

    }

Lua Code 

   

    local pred= NSPredicate:predicateWithFormat(toobjc("SELF MATCHES %@ "),toobjc("[0-9]{0,25}+$"));

 

       is not work!!! Help me!

Benjamin Tolputt

unread,
Mar 7, 2013, 2:24:16 AM3/7/13
to ipho...@googlegroups.com
iPhone Wax doesn't deal well (or really, at all) with variable argument functions like predicateWithFormat. When it comes to things like this, I write a quick wrapper in Obj-C and use that in the Lua code. Something like this should work:

Obj-C
@implementation NSPredicate (LuaHacks)
+ (NSPredicate *)predicateWithFormat:(NSString *)format varArg1:(NSString*)varArg1
{
return [NSPredicate predicateWithFormat:format, varArg1];
}

then, in Lua, you use it as:

local pred = NSPredicate:predicateWithFormat_varArg1("SELF MATCHES %@ ", "[0-9]{0,25}+$")

Hope this helps

Dave Wang

unread,
Mar 7, 2013, 2:37:48 AM3/7/13
to ipho...@googlegroups.com
Thinks!
Reply all
Reply to author
Forward
0 new messages