Ejemplo n.º 1
0
Assembly *LSLuaState::loadExecutableAssembly(const utString& assemblyName, bool absPath)
{
    // executables always in bin
    utString filePath;

    if (!absPath)
    {
        filePath = "./bin/";
    }

    filePath += assemblyName;

    if (!strstr(filePath.c_str(), ".loom"))
    {
        filePath += ".loom";
    }

    const char *buffer   = NULL;
    long       bufferSize;
    LSMapFile(filePath.c_str(), (void **)&buffer, &bufferSize);

    lmAssert(buffer && bufferSize, "Error loading executable: %s, unable to map file", assemblyName.c_str());

    Assembly* assembly = loadExecutableAssemblyBinary(buffer, bufferSize);

	LSUnmapFile(filePath.c_str());

    lmAssert(assembly, "Error loading executable: %s", assemblyName.c_str());

	assembly->freeByteCode();
	
	return assembly;
}
Ejemplo n.º 2
0
Assembly *LSLuaState::loadExecutableAssembly(const utString& assemblyName, bool absPath)
{
    // executables always in bin
    utString filePath;

    if (!absPath)
    {
        filePath = "./bin/";
    }

    filePath += assemblyName;

    if (!strstr(filePath.c_str(), ".loom"))
    {
        filePath += ".loom";
    }

    Assembly   *assembly = NULL;
    const char *buffer   = NULL;
    long       bufferSize;
    LSMapFile(filePath.c_str(), (void **)&buffer, &bufferSize);

    lmAssert(buffer && bufferSize, "Error loading executable: %s, unable to map file", assemblyName.c_str());

    utByteArray headerBytes;

    headerBytes.allocateAndCopy((void *)buffer, sizeof(unsigned int) * 4);

    // we need to decompress
    lmAssert(headerBytes.readUnsignedInt() == LOOM_BINARY_ID, "binary id mismatch");
    lmAssert(headerBytes.readUnsignedInt() == LOOM_BINARY_VERSION_MAJOR, "major version mismatch");
    lmAssert(headerBytes.readUnsignedInt() == LOOM_BINARY_VERSION_MINOR, "minor version mismatch");
    unsigned int sz = headerBytes.readUnsignedInt();

    utByteArray bytes;
    bytes.resize(sz);

    unsigned int readSZ = sz;

    int ok = uncompress((Bytef *)bytes.getDataPtr(), (uLongf *)&readSZ, (const Bytef *)((unsigned char *)buffer + sizeof(unsigned int) * 4), (uLong)sz);

    lmAssert(ok == Z_OK, "problem uncompressing executable assembly");
    lmAssert(readSZ == sz, "Read size mismatch");

    assembly = loadAssemblyBinary(&bytes);

    LSUnmapFile(filePath.c_str());

    lmAssert(assembly, "Error loading executable: %s", assemblyName.c_str());

    return assembly;
}