Last active
May 18, 2019 02:24
-
-
Save Superstar64/9e398b6b1be74a95a0218aa8839a5a6f to your computer and use it in GitHub Desktop.
Mustache Templates with C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdint.h" | |
#include "stdlib.h" | |
typedef struct { | |
int* ptr; | |
size_t length; | |
} NFXHICQ_; | |
NFXHICQ_ create_NFXHICQ_(int* ptr, size_t length){ | |
NFXHICQ_ array = { .ptr = ptr, .length = length }; | |
return array; | |
} | |
typedef struct { | |
float* ptr; | |
size_t length; | |
} MZWG6YLUBI______; | |
MZWG6YLUBI______ create_MZWG6YLUBI______(float* ptr, size_t length){ | |
MZWG6YLUBI______ array = { .ptr = ptr, .length = length }; | |
return array; | |
} | |
int main(){ | |
NFXHICQ_ array = create_NFXHICQ_(malloc(5*sizeof(int)),5); | |
return 0; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdint.h" | |
#include "stdlib.h" | |
{{#types}} | |
typedef struct { | |
{{{type}}}* ptr; | |
size_t length; | |
} {{id}}; | |
{{id}} {{create_id}}({{{type}}}* ptr, size_t length){ | |
{{id}} array = { .ptr = ptr, .length = length }; | |
return array; | |
} | |
{{/types}} | |
{{#names}} | |
int main(){ | |
{{int[]}} array = {{new int[]}}(malloc(5*sizeof(int)),5); | |
return 0; | |
} | |
{{/names}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mustache = mustache.js | |
array.c: array.mustache.c | |
$(mustache) types.json $< > $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"types":[ | |
{ | |
"type":"int", | |
"id":"NFXHICQ_", | |
"create_id":"create_NFXHICQ_" | |
}, | |
{ | |
"type":"float", | |
"id":"MZWG6YLUBI______", | |
"create_id":"create_MZWG6YLUBI______" | |
} | |
], | |
"names":{ | |
"int[]":"NFXHICQ_", | |
"new int[]":"create_NFXHICQ_", | |
"float[]":"MZWG6YLUBI______", | |
"new float[]":"create_MZWG6YLUBI______" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment