当前位置 : 主页 > 网络编程 > lua >

Lua C api:处理大量数据

来源:互联网 收集:自由互联 发布时间:2021-06-23
我在代码中处理皮秒(数字 10 ^ 12). 将数据传递给Lua的C代码(atime和eventid都是size_t类型) lua_getglobal ( luactx, "timer_callback" );lua_pushunsigned ( luactx, atime );lua_pushunsigned ( luactx, eventid );lua_pcall ( l
我在代码中处理皮秒(数字> 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, 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补丁,这将更改整数类型.

网友评论