#How do i make function accept a tuple type as the argument type?

1 messages · Page 1 of 1 (latest)

spare vortex
#

i need something like this:

pub fn TupleThing(arg: tuple) void
{
 //...
}

what do i put instead of tuple?

#

i want to put any tuple in it

#

and i dont want to use anytype

dawn elk
#

struct{T, U}

#

so you can do arg.@"0" for T and arg."1" for U

spare vortex
#

i dont care what the T and U are

dawn elk
#

so any tuple?

spare vortex
#

yeah

dawn elk
#

with the same type of value for each index?

#

or differing

spare vortex
#

any

#

anything that is made with .{ stuff here }

dawn elk
#

I think you might have to use anytype then because its any type in the tuple

#

what's your usecase

spare vortex
#
pub fn CompileError(comptime message: []const u8, args: anytype) error{COMPILEERROR}
{
    std.debug.print("[SYNTAX ERROR]: " ++ message ++ "\n",args);
    return error.COMPILEERROR;
}
#

i apparently used this function wrong somewhere

#

but the compiler wont tell me

#

and instead will tell me that the fmt function needs a tuple (duh)

dawn elk
#

it seems to work for me

#

oh wait I'm on 0.11 hold on

spare vortex
#

im also on 0.11.0

#

i used this function wrong somewhere but i used it MANY times

dawn elk
#

-freference-trace

spare vortex
#

any way to print the call stack

#

how do i use that?

#

it doesnt work with zig build

#

where do i put it in my build.zig

dawn elk
#

It might be called something else

#

I remember using -freference-trace with zig build so I'm not sure

spiral lark
#

I think that you can specify the member like args{.@"0"} since tuple members don't have names
Don't take this seriously, I haven't woken up yet

kindred grotto
#

-freference-trace is unfortunately broken on 0.11, you need to upgrade to 0.12.0 master for good traces

#

you can pass it when using zig build, i.e. zig build run -freference-trace

worthy abyss