コード例 #1
0
ファイル: CLuaMain.cpp プロジェクト: Gothem/mtasa-blue
void CLuaMain::InitVM ( void )
{
    assert( !m_luaVM );

    // Create a new VM
    m_luaVM = lua_open ();
    m_pLuaManager->OnLuaMainOpenVM( this, m_luaVM );

    // Set the instruction count hook
    lua_sethook ( m_luaVM, InstructionCountHook, LUA_MASKCOUNT, HOOK_INSTRUCTION_COUNT );

    // Load LUA libraries
    luaopen_base ( m_luaVM );
    luaopen_math ( m_luaVM );
    luaopen_string ( m_luaVM );
    luaopen_table ( m_luaVM );
    luaopen_debug ( m_luaVM );
    luaopen_utf8 ( m_luaVM );

    // Initialize security restrictions. Very important to prevent lua trojans and viruses!
    InitSecurity ();

    // Registering C functions
    CLuaCFunctions::RegisterFunctionsWithVM ( m_luaVM );

    // Create class metatables
    InitClasses ( m_luaVM );

    // Oli: Don't forget to add new ones to CLuaManager::LoadCFunctions. Thanks!

    // create global vars
    lua_pushelement ( m_luaVM, g_pGame->GetMapManager()->GetRootElement() );
    lua_setglobal ( m_luaVM, "root" );

    lua_pushresource ( m_luaVM, m_pResource );
    lua_setglobal ( m_luaVM, "resource" );

    lua_pushelement ( m_luaVM, m_pResource->GetResourceRootElement () );
    lua_setglobal ( m_luaVM, "resourceRoot" );

    // Load pre-loaded lua code
    LoadScript ( szPreloadedScript );
}
コード例 #2
0
int main(int argc, char **argv)
{
    setvbuf(stdout, NULL, _IOLBF, 0);
#ifdef XP_UNIX
    unlimit();
#endif
    fprintf(stdout, "\n");

    unsigned long limit = 0; // no thread limit by default
    char *addr = NULL;
    PRBool log = PR_FALSE;
    LogLevel logLevel = LOGINFO;
    PLOptState *options;
    PRBool secure = PR_FALSE;
    PRBool NSTests = PR_FALSE; // don't execute Netscape tests by default
    PtrList<char> protlist; // list of security protocols
    PtrList<char> configlist; // list of configurations
    RegexList regexlist; // list of Sun tests/regex to load
    RegexList regexcludelist; // list of Sun tests/regex to exclude
    char* suitename = "suite1";
    PRInt32 concurrent = 0; // number of concurrent threads for each test. 0 means sequential, single-threaded
    PRInt32 delay = 0;
    PRInt32 split = 0;
    PRInt32 timeout = 0; // leave timeout unchanged by default
    char* cert=NULL;
    char* certpwd=NULL;
    char* cipherString = NULL;
    char* version = "ENTERPRISE";
    PRInt32 release = 41;
    PRInt32 hsp = 0; // SSL handshake period
    PRBool performance = PR_FALSE;
    PRInt32 maxtm = 0;
    PRUint16 af = PR_AF_INET;
    PRInt32 displayperiod=0;
    PRBool loop = PR_FALSE;

    Logger::logInitialize(logLevel);

    options = PL_CreateOptState(argc, argv, "X:C:h:H:l:c:d:n:w46r:sx:p:o:t:a:e:k:Ng:v:R:QPE:T:L:");
    long repeat = 1;
    while ( PL_GetNextOpt(options) == PL_OPT_OK)
    {
        switch(options->option)
        {
            case 'L':
                loop = PR_TRUE;
                if (options->value)
                    displayperiod  = (PRInt32) atoi(options->value);
                break;

            case 'E':
                if (options->value)
                    protlist.insert(strdup(options->value));
                break;

            case 'T':
                if (options->value)
                    maxtm  = (PRInt32) atoi(options->value);
                break;

            case 'H':
                if (options->value)
                    hsp  = (PRInt32) atoi(options->value);
                break;

            case 'v':
                if (options->value)
                    version = uppercase(strdup(options->value));
                break;

            case 'g':
                if (options->value)
                    configlist.insert(strdup(options->value));
                break;

            case 'x':
                if (options->value)
                    regexlist.add(options->value);
                break;

            case 'X':
                if (options->value)
                    regexcludelist.add(options->value);
                break;

            case 'w':
                log = PR_TRUE;
                break;

            case 'r':
                if (options->value)
                    repeat = atol(options->value);
                break;

            case 'e':
                if (options->value)
                    timeout = atol(options->value);
                break;

            case 'o':
                if (options->value)
                    split = atol(options->value);
                break;

            case 't':
                if (options->value)
                    delay = atol(options->value);
                break;

            case 'd':
                if (options->value)
                   suitename = strdup(options->value);
                break;

            case 'a':
                if (options->value)
                    arch = strdup(options->value);
                break;

            case 'N':
                NSTests = PR_TRUE;
                break;

            case 'h':
                if (options->value)
                    addr = strdup(options->value);
                break;

            case 'p':
                if (options->value)
                    concurrent = atol(options->value);
                else
                    concurrent = 1; // 1 thread per test
                break;

            case 'P':
                performance = PR_TRUE; // meaure performance only
                break;

            case 'l':
                if (options->value)
                    logLevel = (LogLevel)atoi(options->value);
                break;

            case 'R':
                if (options->value)
                    release = (PRInt32) atoi(options->value);
                break;

            case 's':
                secure = PR_TRUE;
                break;

            case 'n':
                if (options->value)
                    cert = strdup(options->value);
                break;

            case 'k':
                if (options->value)
                    certpwd = strdup(options->value);
                break;

            case 'c':
		if (options->value) {
                  cipherString = strdup(options->value);
                  if (PR_TRUE != EnableCipher(cipherString))
                  {
                         Logger::logError(LOGINFO, "Invalid cipher specified.\n");
                   };
                 }
 		 break;


            case 'C':
                if (options->value)
                    limit = atol(options->value);
                else
                    limit = 0; // no thread limit
                break;

	    case 'Q':
		printCipherOptions();
		break;

	    case '6':
                af = PR_AF_INET6;
		break;

	    case '4':
                af = PR_AF_INET;
		break;

        };
    };

    SecurityProtocols secprots;

    if (PR_TRUE == secure)
    {
        NSString str;
        str.append(suitename);
        str.append("/certs/client");
        secure = InitSecurity((char*)str.data(),
            cert,
            certpwd);
        if (PR_TRUE != secure)
            Logger::logError(LOGINFO, "Unable to initialize security.\n");

        if (protlist.entries())
        {
            secprots = protlist;
        };
    };

    PL_DestroyOptState(options);

    Logger::logInitialize(logLevel);
    nstime_init();

    if (!addr)
    {
        usage(argv[0]);
        return -1;
    };

    HttpServer server(addr, af);
    server.setSSL(secure);
    
    if (PR_FALSE == NSTests)
    {
        if (alltests)
            alltests->clear(); // cancel all the Netscape tests
        if (!regexlist.length())
            regexlist.add(".*");
    };

    if (!configlist.entries())
        configlist.insert("COMMON"); // if no config is specified, select default COMMON configuration

    Engine::globaltimeout = PR_TicksPerSecond()*timeout;

    SunTestSuite suite(configlist, suitename, regexlist, regexcludelist, arch, version, release, log, PR_TicksPerSecond()*timeout, split, delay, hsp, secprots, maxtm);
    PRInt32 percent = suite.runTests(server, concurrent, repeat, limit, performance, loop, displayperiod);

    return percent;
};