Code: Select all
v.s = " 1234"
t = CocoaMessage(0, 0, "NSString stringWithFormat:$", @"Test %S", ":$", @v)
If t
a.s = PeekS(CocoaMessage(0, t, "UTF8String"), -1, #PB_UTF8)
EndIf
Debug a
Code: Select all
v.s = " 1234"
t = CocoaMessage(0, 0, "NSString stringWithFormat:$", @"Test %S", ":$", @v)
If t
a.s = PeekS(CocoaMessage(0, t, "UTF8String"), -1, #PB_UTF8)
EndIf
Debug a
Yes, CocoaMessage relies on NSInvocation which does not support variadic methods.Rinzwind wrote:Problems with variable argument list..
Code: Select all
ImportC ""
CFStringCreateWithCString(alloc, cStr.p-utf8, encoding = #kCFStringEncodingUTF8)
CFStringCreateWithFormat1(alloc, formatOptions, format, arg1) As "_CFStringCreateWithFormat"
CFStringCreateWithFormat2(alloc, formatOptions, format, arg1, arg2) As "_CFStringCreateWithFormat"
CFStringGetCharacters(theString, location, length, *buffer)
CFRelease(cf)
EndImport
Procedure.s CFStringGetString(theString)
Protected Length.i = CFStringGetLength_(theString)
Protected Dim Buffer.u(Length)
CFStringGetCharacters(theString, 0, Length, @Buffer())
ProcedureReturn PeekS(@Buffer())
EndProcedure
v.s = "1234"
Format = CFStringCreateWithCString(0, "Test %S")
FormattedString = CFStringCreateWithFormat1(0, 0, Format, @v)
Debug CFStringGetString(FormattedString)
CFRelease(FormattedString)
CFRelease(Format)
Format = CFStringCreateWithCString(0, "Test %S [%i]")
FormattedString = CFStringCreateWithFormat2(0, 0, Format, @v, 1234)
Debug CFStringGetString(FormattedString)
CFRelease(FormattedString)
CFRelease(Format)
IMP is the address of the implementation itself.Rinzwind wrote:IMP?
Code: Select all
ImportC ""
method_invoke1(receiver, m, arg1, arg2) As "_method_invoke"
method_invoke2(receiver, m, arg1, arg2, arg3.d) As "_method_invoke"
EndImport
NSStringClass = objc_getClass_("NSString")
Selector = sel_registerName_("stringWithFormat:")
Method = class_getClassMethod_(NSStringClass, Selector)
v.s = "1234"
Format = CocoaMessage(0, 0, "NSString stringWithString:$", @"Test %S")
FormattedString = method_invoke1(NSStringClass, Method, Format, @v)
Debug PeekS(CocoaMessage(0, FormattedString, "UTF8String"), -1, #PB_UTF8)
Format = CocoaMessage(0, 0, "NSString stringWithString:$", @"Test %S [%f]")
FormattedString = method_invoke2(NSStringClass, Method, Format, @v, 12.34)
Debug PeekS(CocoaMessage(0, FormattedString, "UTF8String"), -1, #PB_UTF8)
Code: Select all
name.s = "Apple"
weight.f = 100.5
SQL.s = Format("INSERT INTO food (name, weight) VALUES ('%s', %.3f)", @name, @weight)
Debug SQL