我正在尝试从Dart原生扩展中调用const Duration
构造函数。我如何使用Dart_New
C函数来调用此构造函数?
我尝试像其他任何Dart_New
电话一样调用它,但我收到Incorrect number of arguments
错误。
答案 0 :(得分:1)
以下代码片段来自伟大的oracle.dart库,用于与Oracle数据库连接。它从结果集中读取Oracle日期,并使用6个构造函数参数创建一个新的Dart DateTime
对象。
void OracleResultSet_getDate(Dart_NativeArguments args) {
Dart_EnterScope();
auto rs = getThis<occi::ResultSet>(args);
int64_t index = getDartArg<int64_t>(args, 1);
occi::Date date;
try {
date = rs->getDate(index);
} CATCH_SQL_EXCEPTION
int year;
unsigned int month;
unsigned int day;
unsigned int hour;
unsigned int min;
unsigned int seconds;
date.getDate(year, month, day, hour, min, seconds);
std::vector<Dart_Handle> dargs;
dargs.push_back(Dart_NewInteger(year));
dargs.push_back(Dart_NewInteger(month));
dargs.push_back(Dart_NewInteger(day));
dargs.push_back(Dart_NewInteger(hour));
dargs.push_back(Dart_NewInteger(min));
dargs.push_back(Dart_NewInteger(seconds));
Dart_Handle lib = GetDartLibrary("dart:core");
Dart_Handle type = HandleError(Dart_GetType(lib, Dart_NewStringFromCString("DateTime"), 0, NULL));
Dart_Handle obj = HandleError(Dart_New(type, Dart_Null(), 6, &dargs[0]));
Dart_SetReturnValue(args, obj);
Dart_ExitScope();
}