diff options
| author | Ganesh Viswanathan <dev@genotrance.com> | 2019-12-21 12:20:33 -0600 |
|---|---|---|
| committer | Ganesh Viswanathan <dev@genotrance.com> | 2019-12-21 12:20:33 -0600 |
| commit | 3fcc3b9526a8afe4c8caa75b15ad074dde6dc63c (patch) | |
| tree | 351bb055d46a94eff52c76987647cc2032ed8839 | |
| parent | 421bfdc53fd8f56e92827680253a6ddaaa53c8cf (diff) | |
| download | nimterop-issue75.tar.gz nimterop-issue75.zip | |
Fix #75 - support char and char* #definesissue75
| -rw-r--r-- | nimterop/getters.nim | 7 | ||||
| -rw-r--r-- | tests/include/test.h | 2 | ||||
| -rw-r--r-- | tests/lzma.nim | 5 | ||||
| -rw-r--r-- | tests/tnimterop_c.nim | 2 |
4 files changed, 14 insertions, 2 deletions
diff --git a/nimterop/getters.nim b/nimterop/getters.nim index af3dfa2..4cf5653 100644 --- a/nimterop/getters.nim +++ b/nimterop/getters.nim @@ -203,11 +203,14 @@ proc getPtrType*(str: string): string = str proc getLit*(str: string): string = + # Used to convert #define literals into const let str = str.replace(re"/[/*].*?(?:\*/)?$", "").strip() - if str.contains(re"^[\-]?[\d]*[.]?[\d]+$") or - str.contains(re"^0x[\da-fA-F]+$"): + if str.contains(re"^[\-]?[\d]*[.]?[\d]+$") or # decimal + str.contains(re"^0x[\da-fA-F]+$") or # hexadecimal + str.contains(re"^'[[:ascii:]]'$") or # char + str.contains(re"""^"[[:ascii:]]+"$"""): # char * return str proc getNodeVal*(nimState: NimState, node: TSNode): string = diff --git a/tests/include/test.h b/tests/include/test.h index 667f384..b22e2d8 100644 --- a/tests/include/test.h +++ b/tests/include/test.h @@ -9,6 +9,8 @@ extern "C" { #define TEST_INT 512 #define TEST_FLOAT 5.12 #define TEST_HEX 0x512 +#define TEST_CHAR 'a' +#define TEST_STR "hello world" #ifdef __APPLE__ #define OSDEF 10 diff --git a/tests/lzma.nim b/tests/lzma.nim index 4f6c41a..1cc6aa0 100644 --- a/tests/lzma.nim +++ b/tests/lzma.nim @@ -8,6 +8,11 @@ const static: cDebug() + cSkipSymbol(@[ + "PRIX8", "PRIX16", "PRIX32", + "PRIXLEAST8", "PRIXLEAST16", "PRIXLEAST32", + "PRIXFAST8" + ]) when defined(envTest): setDefines(@["lzmaStd"]) diff --git a/tests/tnimterop_c.nim b/tests/tnimterop_c.nim index fb1505a..319c766 100644 --- a/tests/tnimterop_c.nim +++ b/tests/tnimterop_c.nim @@ -46,6 +46,8 @@ cImport cSearchPath "test.h" check TEST_INT == 512 check TEST_FLOAT == 5.12 check TEST_HEX == 0x512 +check TEST_CHAR == 'a' +check TEST_STR == "hello world" when defined(osx): check OSDEF == 10 |
