加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Lua C api:处理大量数据

发布时间:2020-12-14 21:47:00 所属栏目:大数据 来源:网络整理
导读:我在代码中处理皮秒(数字 10 ^ 12). 将数据传递给Lua的C代码(atime和eventid都是size_t类型) lua_getglobal ( luactx,"timer_callback" );lua_pushunsigned ( luactx,atime );lua_pushunsigned ( luactx,eventid );lua_pcall ( luactx,2,0 ); Lua功能 functi
我在代码中处理皮秒(数字> 10 ^ 12).
将数据传递给Lua的C代码(atime和eventid都是size_t类型)

lua_getglobal ( luactx,"timer_callback" );
lua_pushunsigned ( luactx,atime );
lua_pushunsigned ( luactx,eventid );
lua_pcall ( luactx,2,0 );

Lua功能

function timer_callback(time,eventid)  
  if eventid == TX_CLOCK then
  out_log(tostring(time)) --result is random garbage
  set_callback(time + 1000000000000,TX_CLOCK)
  return
  end  
end

我尝试使用lua_pushnumber,但结果是lua我得到了负数.

解决方法

Lua,从5.3开始,支持lua_Integer,默认为64位.从 reference manual:

lua_Integer

typedef … lua_Integer;

The type of integers in Lua.

By default this type is long long (usually a 64-bit two-complement integer),but that can be changed to long or int,usually a 32-bit two-complement integer. (See LUA_INT in luaconf.h.)
Lua also defines the constants LUA_MININTEGER and LUA_MAXINTEGER,with the minimum and the maximum values that fit in this type.

通过编辑luaconf.h,可以相当容易地强制使用Lua 5.2 lua使用不同的数字类型.数字类型定义为LUA_NUMBER.

对于lua 5.1,您可以安装lnum补丁,这将更改整数类型.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读