var ref = require('ref') var StructType = require('ref-struct') // define the time types var time_t = ref.types.long var suseconds_t = ref.types.long // define the "timeval" struct type var timeval = StructType({ tv_sec: time_t, tv_usec: suseconds_t }) // now we can create instances of it var tv = new timeval With node-ffi This gets very powerful when combined with node-ffi to invoke C functions: var ffi = require('ffi') var tv = new timeval gettimeofday(tv.ref(), null) Progressive API You can build up a Struct "type" incrementally (useful when interacting with a parser) using the defineProperty() function. But as soon as you create an instance of the struct type, then the struct type is finalized, and no more properties may be added to it. var ref = require('ref') var StructType = require('ref-struct') var MyStruct = StructType() MyStruct.defineProperty('width', ref.types.int) MyStruct.defineProperty('height', ref.types.int) var i = new MyStruct({ width: 5, height: 10 }) MyStruct.defineProperty('weight', ref.types.int) // AssertionError: an instance of this Struct type has already been created, cannot add new "fields" anymore // at Function.defineProperty (/Users/nrajlich/ref-struct/lib/struct.js:180:3)

































- 1


- 粉丝: 0
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- Java课程设计方案报告-酒店客房管理系统.doc
- 各国强化工业互联网战略标准化成重要切入点.docx
- ANSYS有限元软件建模基础.ppt
- 互联网+对高职学生思想政治教育的影响及其应对探析.docx
- 地铁弱电系统IP网络分配建议方案.docx
- 基于虚拟现实技术的网络会展发展展望.docx
- 数学物理化学生物地理常用软件介绍.doc
- 通信行业发展情况分析-行业集中度整体趋势上行.docx
- 大学设计方案松下FPC型PLC实现交通灯控制大学方案.doc
- 单片机乳化物干燥过程控制系统设计方案.docx
- 物联网工程专业C++程序设计教学改革探索.docx
- 单片机研究分析报告路抢答器.doc
- PLC控制的生活给水泵系统设计.doc
- 非授权移动接入在GSM网络应用中的安全分析.docx
- 2019年二级建造师建设工程项目管理精品小抄.doc
- 《数据库系统》教学设计.doc


