Skip to content

Commit de726de

Browse files
committed
fix: add support of handless wrappers
1 parent 27f47c6 commit de726de

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

schemas/plugin.schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@
356356
"handleType": {
357357
"type": "string",
358358
"description": "The data type used for the underlying handle that this class wraps. Typically ptr64 or ptr32, but may support other types depending on the resource.",
359-
"enum": ["bool", "char8", "char16", "int8", "int16", "int32", "int64", "uint8", "uint16", "uint32", "uint64", "ptr64", "ptr32", "float", "double"]
359+
"enum": ["void", "bool", "char8", "char16", "int8", "int16", "int32", "int64", "uint8", "uint16", "uint32", "uint64", "ptr64", "ptr32", "float", "double"]
360360
},
361361
"invalidValue": {
362362
"type": "string",
@@ -375,7 +375,7 @@
375375
"minItems": 1
376376
},
377377
"destructor": {
378-
"type": "string",
378+
"type": ["string", "null"],
379379
"description": "The method name used to destroy instances of this class and release resources. Called automatically when the object goes out of scope in RAII-supporting languages. Must reference an existing method in the 'methods' array.",
380380
"pattern": "^[a-zA-Z_][a-zA-Z0-9_]*$",
381381
"minLength": 1

src/core/class.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const std::string& Class::GetName() const noexcept {
3333
}
3434

3535
ValueType Class::GetHandleType() const noexcept {
36-
return _impl->handleType.value_or(ValueType::Pointer);
36+
return _impl->handleType.value_or(ValueType::Void);
3737
}
3838

3939
const std::string& Class::GetInvalidValue() const noexcept {

src/core/manifest.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ namespace {
262262
}
263263

264264
// Validate Binding
265-
Result<void> ValidateBinding(const Binding::Impl& binding, const std::string& context) {
265+
Result<void> ValidateBinding(const Binding::Impl& binding, const std::string& context, const std::optional<ValueType>& handleType = std::nullopt) {
266266
if (binding.name.empty()) {
267267
return MakeError("{}: Binding name cannot be empty", context);
268268
}
@@ -279,6 +279,12 @@ namespace {
279279
return MakeError("{}: Binding '{}' has invalid method name '{}'", context, binding.name, binding.method);
280280
}
281281

282+
// Check if handleless classes have instance methods
283+
bool isHandleless = handleType.value_or(ValueType::Void) == ValueType::Void;
284+
if (isHandleless && binding.bindSelf.value_or(false)) {
285+
return MakeError("{}: Binding '{}': handleless classes (handleType is void/empty) cannot have instance methods (bindSelf=true)", context, binding.name);
286+
}
287+
282288
// Validate parameter aliases if present
283289
if (binding.paramAliases) {
284290
for (size_t i = 0; i < binding.paramAliases->size(); ++i) {
@@ -318,6 +324,14 @@ namespace {
318324
return MakeError("Invalid class name: {}", classObj.name);
319325
}
320326

327+
// Check if this is a handleless class
328+
bool isHandleless = classObj.handleType.value_or(ValueType::Void) == ValueType::Void;
329+
330+
// Handleless classes cannot have constructors or destructors
331+
if (isHandleless && (classObj.constructors || classObj.destructor)) {
332+
return MakeError("Class '{}': handleless classes cannot have constructors or destructors", classObj.name);
333+
}
334+
321335
// Validate constructors if present
322336
if (classObj.constructors) {
323337
if (classObj.constructors->empty()) {
@@ -362,7 +376,8 @@ namespace {
362376

363377
if (auto result = ValidateBinding(
364378
*binding._impl,
365-
std::format("Class '{}'", classObj.name)
379+
std::format("Class '{}'", classObj.name),
380+
classObj.handleType
366381
);
367382
!result) {
368383
return result;

0 commit comments

Comments
 (0)