jmcnamara / libxlsxwriter

A C library for creating Excel XLSX files.
https://libxlsxwriter.github.io
Other
1.51k stars 333 forks source link

make header declarations robust to my broken C parser #320

Closed mwette closed 3 years ago

mwette commented 3 years ago

In styles.h exists the declaration

void lxw_styles_write_rich_font(lxw_styles *lxw_styles, lxw_format *format);

I'm (sheepishly) asking that the variable name lxw_styles not be a typedef name, which my API generator can't parse. For example, change lsw_styles *lxw_styles to lxw_styles *styles.

My API generator works like the tool swig: it reads header files and generates API wrapper code for Guile (GNU's Scheme implementation). I know the bug is my parser, but it's a realy hard fix.

jmcnamara commented 3 years ago

Sure. No problem. Fixed on master.

mwette commented 3 years ago

Thanks! From this:

(define-ffi-module (ffi xlsxwriter)
  #:include '("xlsxwriter.h") 
  #:library '("libxlsxwriter") 
  #:inc-filter (lambda (f p) (string-contains p "xlsxwriter" 0))
  #:inc-dirs '("/usr/local/include"))

my tool (nyacc's ffi-helper) generates several 1000's lines of scheme code using Guile's API for libffi. Then a user can do this:

(use-modules (ffi xlsxwriter))
(use-modules (system ffi-help-rt))

(define workbook (workbook_new "xlsxdemo.xlsx"))
(define worksheet (workbook_add_worksheet workbook NULL))

(define format (workbook_add_format workbook))
(format_set_bold format)
(worksheet_set_column worksheet 0 0 20 NULL)
(worksheet_write_string worksheet 0 0 "Hello" NULL)
(worksheet_write_string worksheet 1 0 "World" NULL)
(worksheet_write_number worksheet 2 0 123 NULL)
(worksheet_write_number worksheet 3 0 123.456 NULL)
(worksheet_insert_image worksheet 1 2 "xlsxlogo.png")
(workbook_close workbook)
jmcnamara commented 3 years ago

That's really cool.