進階 API

本節列出不適合一般使用的 API,但在某些情況下可能對開發人員有用的 API。這些包括難以或複雜使用的 API,或主要用於開發 Emscripten 核心的開發人員的 API。

settings.js

settings.js 包含編譯器在各處使用的預設值和選項。

警告

許多 settings.js 選項非常脆弱 - 某些選項組合,以及某些選項與某些原始碼一起使用,可能會導致 Emscripten 嚴重失敗。這適用於「進階使用者」,甚至可能僅適用於開發 Emscripten 本身的人員。

settings.js 中的選項通常設定為 emcc 的命令列參數

emcc -sOPT=VALUE

雖然可以手動編輯 settings.js,但這是非常不建議的。一般而言,settings.js 定義了不應修改的低階選項。另請注意,編譯器會根據其他設定變更某些選項。例如,ASSERTIONS 預設為啟用,但在最佳化建置 (-O1+) 中停用。

注意

如需有關哪些選項可用於設定 Emscripten 的詳細資訊,請閱讀 src/settings.js 或造訪 emsettings 頁面

preamble.js

以下進階 API 記錄在 preamble.js 中。

allocate(slab, allocator)

這被標記為內部,因為它很難使用 (它已針對多個語法進行最佳化,以節省產生的程式碼中的空間)。一般而言,開發人員應使用 _malloc() 配置記憶體,並使用 setValue() 等初始化它,但在某些情況下,此函式可能對進階開發人員有用。

引數
  • slab – 資料陣列或數字。如果是數字,則為要配置的區塊大小 (以位元組為單位)。

  • allocator – 如何配置記憶體,請參閱 ALLOC_*

進階檔案系統 API

檔案系統 API 涵蓋了與大多數開發人員相關的公用 API。以下函式僅適用於進階使用案例 (例如,編寫新的本機檔案系統) 或舊版檔案系統相容性。

FS.hashName(parentid, name)
FS.hashAddNode(node)
FS.hashRemoveNode(node)
FS.lookupNode(parent, name)
FS.createNode(parent, name, mode, rdev)
FS.destroyNode(node)
FS.isRoot(node)
FS.isMountpoint(node)
FS.isFIFO(node)
FS.nextfd()
FS.getStream(fd)
FS.createStream(stream, fd)
FS.closeStream(fd)
FS.getStreamFromPtr(ptr)
FS.getPtrForStream(stream)
FS.major(dev)
FS.minor(dev)
FS.getDevice(dev)
FS.getMounts(mount)
FS.lookup(parent, name)
FS.mknod(path, mode, dev)
FS.create(path, mode)
FS.allocate(stream, offset, length)
FS.mmap(stream, buffer, offset, length, position, prot, flags)
FS.ioctl(stream, cmd, arg)
FS.staticInit()
FS.quit()
FS.indexedDB()
FS.DB_NAME()

僅適用於進階使用者。

FS.getMode(canRead, canWrite)
FS.findObject(path, dontResolveLastLink)
FS.createPath(parent, path, canRead, canWrite)
FS.createFile(parent, name, properties, canRead, canWrite)
FS.createDataFile(parent, name, data, canRead, canWrite, canOwn)
FS.createDevice(parent, name, input, output)
FS.forceLoadFile(obj)

舊版 v1 相容性函式。

還有少數額外的旗標模式

  • rs

  • xw

  • xw+

  • xa

  • xa+