scroll/src/deno/ffi.ts

42 lines
760 B
JavaScript
Raw Normal View History

2023-11-01 15:05:31 -04:00
// Deno-specific ffi code
// Determine library extension based on
// your OS.
// import { termiosStruct } from "../common/termios.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,
);
export const { tcgetattr, tcsetattr, cfmakeraw} = cStdLib.symbols;
export const getPointer = Deno.UnsafePointer.of;