[Q] unable to bind to foreign handler

LiveCode Builder is a language for extending LiveCode's capabilities, creating new object types as Widgets, and libraries that access lower-level APIs in OSes, applications, and DLLs.

Moderators: LCMark, LCfraser

Post Reply
shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

[Q] unable to bind to foreign handler

Post by shaosean » Sat Nov 18, 2017 10:17 am

Code: Select all

library tk.shaosean.library.mac.test

use com.livecode.foreign
use com.livecode.objc

metadata version is "1.0.0"
metadata author is "shaosean.tk"
metadata title is "test"

---------------------

private foreign handler NSUserNotificationAlloc() returns ObjcRetainedId binds to "objc:NSUserNotification.+alloc"
private foreign handler NSUserNotificationInit(in Obj as ObjcId) returns ObjcId binds to "objc:NSUserNotification.-init"
private foreign handler NSUserNotificationSetTitle(in Obj as ObjcId, in Title as ObjcId) returns nothing binds to "objc:NSUserNotification.-setTitle:"

---------------------


public handler Test() returns nothing
	if the operating system is "mac" then
		unsafe
			variable aNSUserNotification as ObjcObject
			put NSUserNotificationAlloc() into aNSUserNotification
			put NSUserNotificationInit(aNSUserNotification) into aNSUserNotification

			NSUserNotificationSetTitle(aNSUserNotification, StringToNSString("hello"))
		end unsafe
	end if
end handler


end library

Code: Select all

--executing at 4:09:44 AM
--LCB Error	Unable to bind foreign handler tk.shaosean.library.mac.test.NSUserNotificationSetTitle
--Object	Button
--LCB File	test.lcb
--LCB Line	26
From everything I can tell, my code is correct, but for some reason the setTitle: is not binding.. I looked at the code from the MacButton.lcb that ships with LiveCode, and other than the class, the code is identical, but their binding works..

Is this a bug? Is this PEBCAK error? Is it something else?

livecodeali
Livecode Staff Member
Livecode Staff Member
Posts: 192
Joined: Thu Apr 18, 2013 2:48 pm

Re: [Q] unable to bind to foreign handler

Post by livecodeali » Mon Dec 04, 2017 2:19 pm

Bug report, for reference: http://quality.livecode.com/show_bug.cgi?id=20733

Further to my explanation on the above report, you should be able to work around the issue using setValue:forKey:

Code: Select all

private foreign handler NSUserNotificationSetProperty(in Obj as ObjcId, in pValue as ObjcId, in pProp as ObjcId) returns nothing binds to "objc:NSUserNotification.-setValue:forKey:"

NSUserNotificationSetProperty(aNSUserNotification, StringToNSString("hello"), StringToNSString("title"))

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: [Q] unable to bind to foreign handler

Post by shaosean » Mon Dec 04, 2017 3:20 pm

Nice, I'll give that a try. I see that Mark W did a fix for other classes, that work the same.

Thanks for the quick response to this. :-)

Post Reply

Return to “LiveCode Builder”