luat_lib_win32.c 802 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include "luat_base.h"
  2. #include "luat_malloc.h"
  3. #define LUAT_LOG_TAG "win32"
  4. #include "luat_log.h"
  5. extern int win32_argc;
  6. extern char** win32_argv;
  7. static int l_win32_args(lua_State *L) {
  8. int index = luaL_optinteger(L, 1, 2);
  9. lua_newtable(L);
  10. if (win32_argc > index) {
  11. for (size_t i = index; i < win32_argc; i++)
  12. {
  13. //printf("args[%d] %s\n", i, win32_argv[i]);
  14. lua_pushinteger(L, i + 1 - index);
  15. lua_pushstring(L, win32_argv[i]);
  16. lua_settable(L, -3);
  17. }
  18. }
  19. return 1;
  20. }
  21. #include "rotable.h"
  22. static const rotable_Reg reg_win32[] =
  23. {
  24. { "args", l_win32_args, 0},
  25. { NULL, NULL, 0}
  26. };
  27. LUAMOD_API int luaopen_win32( lua_State *L ) {
  28. rotable_newlib(L, reg_win32);
  29. return 1;
  30. }