I have a function which stores the return value from a D function for access by Lua. It looks like this:

int StoreReturn(T)(lua_State* L, T ret)
{
        static if (is(T==bool))
        {
                lua_pushboolean(L, ret?1:0);
                return 1;
        }
        else static if (__traits(isIntegral, T))
        {
                lua_pushnumber(L, cast(double)ret);
                return 1;
        }
        // etc.
        else
        {
                // unsupported return type
                static assert(0);
        }
}

I would like to call it with a function like this:

int CallFunction(R, U...)(lua_State* L, R function(U) func)
{
        U args;
        foreach (i, arg; args)
                arg = ExtractParameter!(U[i],i+1)(L);
        
        return StoreReturn(L, func(args));
}

This works unless func returns void. I have a static if condition that detects and handles the case where R is void, but it would be nice if I could extend StoreReturn to include:

        else static if (is(T==void))
        {
                return 0;
        }

This doesn't work though because parameter types can't be void.

Would it be a good idea to allow void as a valid parameter type for generic code?

Related link: https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=94226

Phil Deets

Reply via email to