size: 756 B
| 1 | #include "djot.h" |
| 2 | #include <stdio.h> |
| 3 | #include <string.h> |
| 4 | #include <assert.h> |
| 5 | #include "lauxlib.h" |
| 6 | |
| 7 | #include "djot_main.inc" |
| 8 | /* unsigned char djot_main_lua[], unsigned int djot_main_lua_len */ |
| 9 | |
| 10 | int main(int argc, char* argv[]) { |
| 11 | int status; |
| 12 | /* Do this once, before any use of the djot library */ |
| 13 | lua_State *L = djot_open(); |
| 14 | if (!L) { |
| 15 | fprintf(stderr, "djot_open returned NULL.\n"); |
| 16 | return -1; |
| 17 | } |
| 18 | |
| 19 | // start array structure |
| 20 | lua_newtable( L ); |
| 21 | |
| 22 | for (int i=1; i<=argc; i++) { |
| 23 | |
| 24 | lua_pushnumber( L, i ); |
| 25 | lua_pushstring( L, argv[i] ); |
| 26 | lua_rawset( L, -3 ); |
| 27 | |
| 28 | } |
| 29 | |
| 30 | lua_setglobal( L, "arg" ); |
| 31 | |
| 32 | status = luaL_dostring(L, (char*)djot_main_lua); |
| 33 | if (status != LUA_OK) { |
| 34 | djot_report_error(L); |
| 35 | } |
| 36 | |
| 37 | djot_close(L); |
| 38 | return 0; |
| 39 | } |
| 40 |