尝试编写一个快速的Unity插件以从剪贴板中获取数据时,有问题的函数如下:
extern "C"
{
const char * _importString()
{
UIPasteboard *result = [UIPasteboard generalPasteboard];
NSString * resultString = [result string];
return [resultString UTF8String];
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我激活该功能时,它给了我以下错误:
GfxDevice: creating device client; threaded=1
Initializing Metal device caps: Apple A9 GPU
Initialize engine version: 2017.1.0f3 (472613c02cf7)
2017-08-26 13:46:21.395230+0100 ProductName[8608:2930827] [Common] _BSMachError: port 5e03; (os/kern) invalid capability (0x14) "Unable to insert COPY_SEND"
2017-08-26 13:46:21.400889+0100 ProductName[8608:2930827] [Common] _BSMachError: port 5e03; (os/kern) invalid capability (0x14) "Unable to insert COPY_SEND"
UnloadTime: 4.034333 ms
ProductName(8608,0x1b8100b40) malloc: *** error …Run Code Online (Sandbox Code Playgroud) 尝试使用GetFunctionPointerForDelegate通过互操作传递函数指针(C# -> C++)。但是,我得到了例外:The specified Type must not be a generic type definition.
据我所知,我没有传递泛型类型定义,在检查委托的类型时,我看到了以下内容:

我写了一个最小的例子并观察到了相同的行为,对于我所缺少的任何建议,我将不胜感激。
using System;
using System.Runtime.InteropServices;
public class MyTestClass
{
public void Foo()
{
Delegate del = new Func<int, int>(Bar);
IntPtr funcPtr = Marshal.GetFunctionPointerForDelegate(del);
}
public int Bar(int a)
{
return 0;
}
}
public class Program
{
public static void Main()
{
var mtc = new MyTestClass();
mtc.Foo();
}
}
Run Code Online (Sandbox Code Playgroud)
可以在 dotnet fiddle 上观察到该问题:https ://dotnetfiddle.net/8Aol9j
Swift的新手,我目前正在通过以下方式传递函数作为可选参数:
import Foundation
func foo()
{
print("Foo")
}
func bar()
{
print("Bar")
}
func dummy()
{
return
}
func myFunc()
{
myFunc(callBack: dummy())
}
func myFunc(callBack: (Void))
{
foo()
callBack
}
myFunc()
myFunc(callBack: bar())
Run Code Online (Sandbox Code Playgroud)
即利用多态性
这似乎是一种微不足道的方法,是否有更好的方法,
谢谢汤姆
编辑:
我知道我可以通过执行以下操作来缩短此时间:
import Foundation
func foo()
{
print("Foo")
}
func bar()
{
print("Bar")
}
func dummy()
{
return
}
func myFunc(callBack: (Void) = dummy())
{
foo()
callBack
}
myFunc()
myFunc(callBack: bar())
Run Code Online (Sandbox Code Playgroud)
但是我仍然会说这是一个微不足道的解决方案