Ejemplo 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;
}
Ejemplo n.º 2
0
int main ( int argc, char **argv )
{
    IupOpen(&argc, &argv);
#ifndef IUPLUA_NO_GL
    IupGLCanvasOpen();
#endif
#ifndef IUPLUA_NO_CD
    IupControlsOpen();
    IupPPlotOpen();
#endif

    lua_open();

    lua_setdebug(1);

    lua_iolibopen( );
    lua_strlibopen( );
    lua_mathlibopen( );

    iuplua_open( );
    iupkey_open( );
#ifndef IUPLUA_NO_GL
    iupgllua_open();
#endif
#ifndef IUPLUA_NO_CD
    iupcontrolslua_open();
    iup_pplotlua_open();
    cdlua_open();
    cdluaiup_open();
#endif
#ifndef IUPLUA_NO_IM
    iupimlua_open();
    imlua_open();
#endif

    if (argc <= 1)
    {
        if(!iuplua_dofile("console3.lua"))
        {
#ifdef TEC_BIGENDIAN
#ifdef TEC_64
#include "loh/console3_be64.loh"
#else
#include "loh/console3_be32.loh"
#endif
#else
#ifdef TEC_64
#ifdef WIN64
#include "loh/console3_le64w.loh"
#else
#include "loh/console3_le64.loh"
#endif
#else
#include "loh/console3.loh"
#endif
#endif
        }
    }
    else
    {
        int ok = 1,
            i  = 1;

        /* Running all .lua given as arguments */
        while(ok & (i < argc))
        {
            ok = iuplua_dofile(argv[i]);
            i++;
        }

        if(!ok)
        {
            return EXIT_FAILURE;
        }
    }

#ifndef IUPLUA_NO_CD
    cdlua_close();
    IupControlsClose();
#endif
    IupClose();

    lua_close();

    return EXIT_SUCCESS;
}
Ejemplo n.º 3
0
int main(int argc, char ** argv)
{
  setExecutablePath(argv[0]);

  lua_State *L = lua_open();

  luaL_openlibs(L);

#if USE_IUP
  iuplua_open(L);
  cdlua_open(L);
  cdluaiup_open(L);

  iupkey_open(L);
  iupimlua_open(L);
  IupImageLibOpen ();
  iupcontrolslua_open(L);
  imlua_open(L);
  imlua_open_process(L);
#endif

  luaopen_pack(L);
  luaopen_lfs(L);
  luaopen_marshal(L);
  luaopen_mime_core(L);
  luaopen_socket_core(L);

  pdfdoc_register(L);
  pdfpage_register(L);
  clipboard_register(L);
  luaopen_system(L);
  luaopen_compare(L);

#if _DEBUG 
  lua_pushboolean(L, true);
  lua_setfield(L, LUA_GLOBALSINDEX, "_DEBUG");
#endif
  
  char luaFile[512] = "";
  char playlistFile[512] = "";
  int beginIndex = 1;
  if (argc > 1)
  {
    int strl = strlen(argv[1]);
    bool isLuaFile = strcmp(&argv[1][strl-4], ".lua") == 0;
    if (isLuaFile)
    {
      beginIndex = 2;
      strcpy_s(luaFile, sizeof(luaFile), argv[1]);
    }
    else if (strcmp(&argv[1][strl-5], ".sing") == 0
      || strcmp(&argv[1][strl-4], ".m3u") == 0
      || strcmp(&argv[1][strl-4], ".txt") == 0)
    {
    }
  }
  if (!luaFile[0])
  {
    lua_pushboolean(L, true);
    lua_setfield(L, LUA_GLOBALSINDEX, "APPLOADED");
	const char* execPath = getExecutablePath();
	sprintf_s(luaFile, sizeof(luaFile), "%s\\%s", execPath, "main.lua");
  }
    
  int temp_int = luaL_loadfile(L,luaFile);
  
  int returnval = 0;
  if (temp_int)
  {
    const char *error = lua_tostring(L, -1);
    printf("Error in file: \"%s\"\n", luaFile);
    printf("%s\n", error);
    returnval = 1;
  }
  else
  {
    const char *error;

    for (int i = beginIndex; i < argc; i++)
      lua_pushstring(L, argv[i]);

    if (docall(L,argc-beginIndex,0))
    {
      error = lua_tostring(L, -1);
      if (error)
        std::cout << error;
      returnval = 1;
    }
  }
  close(L);

  return returnval;
}