PMunch / futhark

Automatic wrapping of C headers in Nim
MIT License
377 stars 20 forks source link

Issues with defines and templates #104

Open mantielero opened 4 months ago

mantielero commented 4 months ago

I am trying to wrap the header file libavutil/channel_layout.h.

By means of:

import futhark,os

importc:
  outputPath currentSourcePath.parentDir / "libavutil" / "channel_layout.nim"
  path "../FFmpeg-release-6.1/libavutil"
  "channel_layout.h"

This part of the header is not in the produced file.

c2nim is a bit closer to the right answer but I don't what would be the required template in this case:

template AV_CHANNEL_LAYOUT_MASK*(nb, m: untyped): void =
  ##  .order
  ## !!!Ignored construct:  AV_CHANNEL_ORDER_NATIVE ,  .nb_channels ( nb ) ,  .u.mask { m } ,  .opaque NULL }
  ## Error: expected ';'!!!

##
##  @name Common pre-defined channel layouts
##  @{
##

const
  AV_CHANNEL_LAYOUT_MONO* = AV_CHANNEL_LAYOUT_MASK(1, AV_CH_LAYOUT_MONO)
  AV_CHANNEL_LAYOUT_STEREO* = AV_CHANNEL_LAYOUT_MASK(2, AV_CH_LAYOUT_STEREO)
  AV_CHANNEL_LAYOUT_2POINT1* = AV_CHANNEL_LAYOUT_MASK(3, AV_CH_LAYOUT_2POINT1)
  AV_CHANNEL_LAYOUT_2_1* = AV_CHANNEL_LAYOUT_MASK(3, AV_CH_LAYOUT_2_1)
  AV_CHANNEL_LAYOUT_SURROUND* = AV_CHANNEL_LAYOUT_MASK(3, AV_CH_LAYOUT_SURROUND)
  AV_CHANNEL_LAYOUT_3POINT1* = AV_CHANNEL_LAYOUT_MASK(4, AV_CH_LAYOUT_3POINT1)
  AV_CHANNEL_LAYOUT_4POINT0* = AV_CHANNEL_LAYOUT_MASK(4, AV_CH_LAYOUT_4POINT0)
  AV_CHANNEL_LAYOUT_4POINT1* = AV_CHANNEL_LAYOUT_MASK(5, AV_CH_LAYOUT_4POINT1)
  AV_CHANNEL_LAYOUT_2_2* = AV_CHANNEL_LAYOUT_MASK(4, AV_CH_LAYOUT_2_2)
  AV_CHANNEL_LAYOUT_QUAD* = AV_CHANNEL_LAYOUT_MASK(4, AV_CH_LAYOUT_QUAD)
  AV_CHANNEL_LAYOUT_5POINT0* = AV_CHANNEL_LAYOUT_MASK(5, AV_CH_LAYOUT_5POINT0)
PMunch commented 4 months ago

It's basically a structure construction, and Futhark unfortunately doesn't handle C macros well. This is a limitation of how C macros are defined. Should be fairly easy to write that template and just use the output from c2nim though.