scroll/src/deno/ffi.ts

45 lines
761 B
JavaScript

// Deno-specific ffi code
import { IFFI } from '../common/types.ts';
let libSuffix = '';
switch (Deno.build.os) {
case 'windows':
libSuffix = 'dll';
break;
case 'darwin':
libSuffix = 'dylib';
break;
default:
libSuffix = 'so.6';
break;
}
const cSharedLib = `libc.${libSuffix}`;
const cStdLib = Deno.dlopen(
cSharedLib,
{
tcgetattr: {
parameters: ['i32', 'pointer'],
result: 'i32',
},
tcsetattr: {
parameters: ['i32', 'i32', 'pointer'],
result: 'i32',
},
cfmakeraw: {
parameters: ['pointer'],
result: 'void',
},
} as const,
);
const { tcgetattr, tcsetattr, cfmakeraw } = cStdLib.symbols;
const DenoFFI: IFFI = {
tcgetattr,
tcsetattr,
cfmakeraw,
getPointer: Deno.UnsafePointer.of,
};
export default DenoFFI;