[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: C - Lua Interfacing and best way to push args
- From: Javier Guerra Giraldez <javier@...>
- Date: Mon, 7 Jul 2014 09:28:08 -0500
On Mon, Jul 7, 2014 at 5:34 AM, Austin Einter <austin.einter@gmail.com> wrote:
> I understand, in C we can write functions with variable number of arguments'
yes, check the va_arg() macros. but that allows you to write a
function that can take a variable number of arguments; AFAIK, there's
no help to _call_ a function without knowing the number and type of
arguments at compile time
in short, the '...' syntax in C means "don't do static checks, just
push the args and hope for the best", and the va_arg() macros pluck
the values from the untyped blob that results in the stack.
> Inside C function, can we find the type of an argument and its values in an
> iterative way, so that we can push the argument to stack.
the problem is that you want to do a dynamic-style call to a
statically-defined function. that means you have two kind of options:
- write a different call for any possible signature and do a huge
switch (or a staged jumper) to choose between them. (i guess this is
your current "expensive" solution)
- manually build the call stack, complying with your compiler exact
value layout; cast your function pointers to a non-argument one and
call it. this would be akin to the reverse of va_arg().
--
Javier