Search
 
SCRIPT & CODE EXAMPLE
 

CPP

swift functions from cpp

// main.swift

private func printGreeting(modifier: UnsafePointer<CChar>) {
    print("Hello (String(cString: modifier))World!")
}

var callbacks = SomeCLibCallbacks(
    printGreeting: { (modifier) in
        printGreeting(modifier: modifier)
    }
)
SomeCLibSetup(&callbacks)

SomeCLibTest()

// SomeCLib.h

#ifndef SomeCLib_h
#define SomeCLib_h

struct SomeCLibCallbacks {
    void (* _Nonnull printGreeting)(const char * _Nonnull modifier);
};
typedef struct SomeCLibCallbacks SomeCLibCallbacks;

extern void SomeCLibSetup(const SomeCLibCallbacks * _Nonnull callbacks);

extern void SomeCLibTest(void);

#endif

// SomeCLib.c

#include "SomeCLib.h"

static SomeCLibCallbacks sCallbacks;

extern void SomeCLibSetup(const SomeCLibCallbacks * callbacks) {
    sCallbacks = *callbacks;
}

extern void SomeCLibTest(void) {
    sCallbacks.printGreeting("Cruel ");
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: Implement a currency converter which ask the user to enter value in Pak Rupees and convert in following: in cpp 
Cpp :: Boats to Save People leetcode solution in c++ 
Cpp :: char to binary 
Cpp :: C++ if...else 
Cpp :: days in a year c++ 
Cpp :: Pawri Meme codechef solution in c++ 
Cpp :: algorithm map values 
Cpp :: C++ operation 
Cpp :: How to make an array dynamically using pointers 
Cpp :: bash script add another user 
Cpp :: Stream Overloading 
Cpp :: c pointer syntax 
Cpp :: python pour débutant 
Cpp :: codeform 
Cpp :: C++ Vector Initialization method 02 
Cpp :: ue4 c++ oncomponentbeginoverlap 
Cpp :: gcd 
Cpp :: 2160. Minimum Sum of Four Digit Number After Splitting Digits leetcode solution in c++ 
Cpp :: qt/c++ exception handler 
Cpp :: rand function c++ 
Cpp :: 1162261467 
Cpp :: hello command not printing in c++ 
Cpp :: Max / Min Stack in c++ using stl in O(1) time and space 
Cpp :: strip whitespace c++ 
Cpp :: for statement in c++ 
Cpp :: what does | mean in c++ 
Cpp :: read from standard input cpp 
C :: remix icon cdn 
C :: manifest orientation portrait 
C :: c program to find area of circle 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =