chibi-scheme
chibi-scheme copied to clipboard
[Feature request] Variadic C functions
It would be nice if there were a way to use the variadic argument machinery from within C, so you don't have to wrap everything scheme.
What specifically do you want to wrap?
For example, if you wanted to create an FFI with list
-like semantics, you have to pass in a list
, you can't just throw all of your parameters at it.
That's not specific, that's just restating the request.
Do you want to be able to wrap existing variadic C functions like printf, and if so which one?
Or do you want to write new variadic functions in C specifically for Chibi, and if so what?
I would like to write new variadic functions, specifically for Chibi; I am creating a modern programming language equivalent of a super old old language called FDO, and need to be able to nest scheme structures, in order to represent graphical data structures for an application to be able to parse and display properly.
man_start_object <trigger, "Welcome">
act_replace_select_action
<
uni_start_stream
sm_m_send_token_arg <"f1", 32-30>
uni_end_stream
>
man_end_object
Since it's a new function specifically for Chibi, why not write it to take a Scheme list? If the primitive is named %act_replace_select_action, it can take a list, and then in Scheme you can write:
(define (act-replace-select-action . args)
(%act_replace_select_action args))
This needs to be in C, because a GUI client will be taking in all of this and making sense of it.
Then you can have 2 C functions: one which takes a Scheme list, and another variadic C function which builds a Scheme list to call the first function.
Although a C function can accept variadic arguments with va_arg, there's no standard way to dynamically generate an argument list for such a C function at runtime.
Chibi's FFI is currently entirely static, so translates directly to C. Allowing dynamic argument lists would require platform-specific assembly (like libffi), which is not something I want to maintain.
Oh, that's the reason. That's fine; I'll come up with logic to unpack a scheme list. I expect posting many more questions on this thread, then. :p
So, question- if I use va_list
, can I get chibi-scheme to give me a list of passed arguments instead? (Probably not, I was just curious.)