Exemplo n.º 1
0
static lua_State* luacom_DoRegistryFile(const char* luaclsid) {
  lua_State* L_inproc = NULL;
  char* fileName;
  char* key = new char[strlen(luaclsid)+18];

  strcpy(key, "CLSID\\");
  strcat(key,luaclsid);
  strcat(key,"\\ScriptFile");

  if(tCOMUtil::GetRegKeyValue(key,&fileName)) {
    L_inproc = luaL_newstate();
    luaL_openlibs(L_inproc);
    #ifdef IUP
      /* iuplua initialization */
      iuplua_open(L_inproc);
      iupkey_open(L_inproc);
      cdlua5_open(L_inproc);
      #ifndef NO_CPICONTROLS
      controlslua_open(L_inproc);
      gllua_open(L_inproc);
      #endif
      #ifdef SPEECH_SDK
      speechlua_open(L_inproc);
      #endif
      #ifdef USE_GLLUA
      gl_open(L_inproc);
      #endif
      iupluaim_open(L_inproc);
    #endif

    luacom_open(L_inproc);
    lua_pushvalue(L_inproc, LUA_REGISTRYINDEX);
    lua_pushstring(L_inproc,"inproc");
    lua_pushboolean(L_inproc,TRUE);
    lua_settable(L_inproc,-3);
    lua_pop(L_inproc,1);

    if(!lua_dofile(L_inproc,fileName)) {
      lua_pushstring(L_inproc,"StartAutomation");
      lua_gettable(L_inproc,-2);
      if(luaCompat_call(L_inproc, 0, 0)) {
        luacom_close(L_inproc);
        lua_close(L_inproc);
        L_inproc = NULL;
      }
    } else {
      luacom_close(L_inproc);
      lua_close(L_inproc);
      L_inproc = NULL;
    }
  }

  delete[] key;
  SAFEDELETEARR(fileName);
  return L_inproc;
}
Exemplo n.º 2
0
extern "C" int luacom_openlib(lua_State* L) {
  luacom_open(L);
  return 0;
}
int main (int argc, char *argv[])
{
  int i;

  OleInitialize(NULL);

  SetConsoleTitle(LUACOM_VERSION);

#if defined(LUA4)
  lua_State *lua_state = lua_open(0);
  lua_baselibopen (lua_state);
  lua_mathlibopen (lua_state);
  lua_iolibopen   (lua_state);
  lua_strlibopen (lua_state);
#elif defined(LUA5)
  lua_State *lua_state = lua_open();
  luaopen_base (lua_state);
  luaopen_math (lua_state);
  luaopen_io   (lua_state);
  luaopen_string (lua_state);
  luaopen_table (lua_state);
#endif

  lua_pushstring(lua_state, "> "); lua_setglobal(lua_state, "_PROMPT");

  luacom_open(lua_state);
  init_windows(lua_state);
  if (argc < 2) {  /* no arguments? */
    if (isatty(0)) {
      printf("%s  %s\n", LUACOM_VERSION, LUACOM_COPYRIGHT);
      manual_input(lua_state, 1);
    }
    else
      ldo(lua_state, lua_dofile, NULL);  /* executes stdin as a file */
  }
  else for (i=1; i<argc; i++) {
    if (argv[i][0] == '-') {  /* option? */
      switch (argv[i][1]) {
        case 0:
          ldo(lua_state, lua_dofile, NULL);  /* executes stdin as a file */
          break;
        case 'i':
          manual_input(lua_state, 1);
          break;
        case 'q':
          manual_input(lua_state, 0);
          break;
        case 'v':
          printf("%s  %s\n(written by %s)\n\n",
                 LUACOM_VERSION, LUACOM_COPYRIGHT, LUACOM_AUTHORS);
          break;
        case 'e':
          i++;
          if (ldo(lua_state, lua_dostring, argv[i]) != 0) {
            fprintf(stderr, "lua: error running argument `%s'\n", argv[i]);
            return 1;
          }
          break;
        default:
          print_message();
          exit(1);
      }
    }
    else if (strchr(argv[i], '='))
      assign(lua_state, argv[i]);
    else {
      int result = ldo(lua_state, lua_dofile, argv[i]);
      if (result) {
        if (result == 2) {
          fprintf(stderr, "lua: cannot execute file ");
          perror(argv[i]);
        }
        exit(1);
      }
    }
  }

  luacom_close(lua_state);
  lua_close(lua_state);

  OleUninitialize();

  return 0;
}