Thursday, December 1, 2022

#1 2022-11-19 11:50:20 pm

technomorph
Member
Registered: 2017-12-14
Posts: 302

Calling "C" Functions in a Framework - Possible?

Is it possible to call "C" style functions from AppleScript?
I've recently start using them in my Objective-C code and find them handy sometimes.
Would love to be able to call them from AppleScript.
But my attempts so far have failed.

In one of my Framework Classes:

Applescript:


#pragma mark TAG CHECKED TYPE STATUS
JREnumDeclare(TagCheckedTypeStatus,
            Checked_None = 0,                    // 0
            Checked_Whitespace = 1 << 0,        // 1
            Checked_EpisodeID = 1 << 1,        // 2
            Checked_CatalogNo = 1 << 2,        // 4
            Checked_Composer = 1 << 3,        // 8
            Checked_Label = 1 << 4            // 16
           /// TRIMMED
);

NSString* TagCheckTypeStatusInfo(TagCheckedTypeStatus aCheckTagType);

and in the .m

Applescript:


NSString* TagCheckTypeStatusInfo(TagCheckedTypeStatus aCheckTagType) {
   NSString* infoHeader = @"CHECK STATUS:";
// TRIMMED
   return [infoHeader infoStringByAddingDetails:infoDetails];
}

Trying from AppleScript fails

Applescript:


use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "DJKTelHelperUtilities"
use scripting additions

-- classes, constants, and enums used
property TagCheckedTypeStatus : a reference to current application's TagCheckedTypeStatus
property Checked_Whitespace : a reference to 1
property Checked_Label : a reference to 4

property aTagCheckedTypeInfo1 : missing value
property aTagCheckedTypeInfo2 : missing value

set aTagCheckedType to Checked_Label
set aTagCheckedTypeInfo1 to TagCheckTypeStatusInfo(aTagCheckedType)
set aTagCheckedTypeInfo2 to current application's TagCheckTypeStatusInfo(aTagCheckedType)

I guess I could add some non-instance methods on a Class that then call
the C-Functions?

Offline

 

#2 2022-11-20 05:34:25 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6798

Re: Calling "C" Functions in a Framework - Possible?

You can call them, provided the types used as arguments or results are bridgeable (so no CSRefs).


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)