lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi, first post and just new to Lua also :))

I am trying to run this FFI libcall (linux).

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

ffi.cdef[[
    int TA_RSI( int            startIdx,
                int            endIdx,
                const double   inReal[],
                int            optInTimePeriod,
                int            *outBegIdx,
                int            *outNBElement,
                double         outReal[] );
]]
----------------------------------------------------------------------------
-- Passing Parameters
----------------------------------------------------------------------------
optInTimePeriod   = 1
startIdx          = 0
endIdx            = 8
maType            = 1
outBegIdx         = ffi.new("int[1]",0) --Pointer set val to zero, therefore ffi.new ?
outNbElement      = ffi.new("int[1]",0) 

----------------------------------------------------------------------------
-- The in/out Array
----------------------------------------------------------------------------
inA     = {[0] = 1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0} -- zerobased array the lib is expecting
outA    = {[0] = 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0}


----------------------------------------------------------------------------
-- Table to Array Constructor
----------------------------------------------------------------------------
inReal  = ffi.new("double[9]", inA )
outReal = ffi.new("double[9]", outA ) -- or this? ->
outReal = ffi.new("double[9]", {})

----------------------------------------------------------------------------
--The Libcall
----------------------------------------------------------------------------
retVal = ta_lib.TA_RSI(startIdx, endIdx, inReal, optInTimePeriod, outBegIdx, outNbElement, outReal)

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
The lib is expecting two prefilled arrays, doing some math with the inReal[] and filling the
outReal[]
with the results (double).
running this script returning a errorcode 2 (bad params).
I was trying a simpler call too without any error but don't know how to access the the outReal[] array.
via type? I am getting a cdata(double[9]) var. how to convert this cdata to a lua-table?

Looked at the docu but can't make it working since I am just start working with Lua.
Any advise or hint where I can crawl further?

best, peter