fxconv: add new return type convention for custom converters

Previously converters had to return:
- 0 on success, having called fxconv.elf() themselves
- 1 on failure

Now they also have the (preferred option) to return:
- a bytes or ObjectData on success, without calling fxconv.elf()
- None of failure
This commit is contained in:
Lephenixnoir 2024-06-02 16:08:03 +02:00
parent 96c035ff4a
commit 8d6bc9c14f
No known key found for this signature in database
GPG key ID: 1BBA026E13FC0495

View file

@ -1178,7 +1178,13 @@ def convert(input, params, target, output=None, model=None, custom=None):
o = convert_libimg_cg(input, params) o = convert_libimg_cg(input, params)
elif custom is not None: elif custom is not None:
for converter in custom: for converter in custom:
if converter(input, output, params, target) == 0: rc = converter(input, output, params, target)
# Old convention: 0 on success, 1 on failure
if rc == 0:
return
# New convention: bytes() or ObjectData() on success
if isinstance(rc, bytes) or isinstance(rc, ObjectData):
elf(rc, output, "_" + params["name"], **target)
return return
raise FxconvError(f'unknown custom resource type \'{t}\'') raise FxconvError(f'unknown custom resource type \'{t}\'')
else: else: