From 7d055b3f0f57fdf48010162ed6ec7bf5e3af3895 Mon Sep 17 00:00:00 2001 From: Ronan Collobert Date: Tue, 7 Feb 2012 21:36:24 +0100 Subject: more dok --- dok/index.dok | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/dok/index.dok b/dok/index.dok index e5a503a..422c606 100644 --- a/dok/index.dok +++ b/dok/index.dok @@ -47,3 +47,45 @@ some of them might be optional, can become very quickly a tedious task. The **wrap** package is here to help the process. Remember however that even though you might be able to treat most complex cases with **wrap**, sometimes it is also good to do everything by hand yourself! + +===== High Level Interface ===== + +**wrap** provides only one class: ''CInterface''. Considering our easy example, a typical usage +would be: +' + +require 'wrap' + +interface = wrap.CInterface.new() + +interface:wrap( + "numel", -- the Lua name + "numel", -- the C function name, here the same + -- now we describe the 'arguments' (or possibly returned values) + { + {name="DoubleTensor"}, + {name="int", creturned=true} -- this one is returned by the C function + } +) + +print(interface:tostring()) + +The wrapper generated by **wrap** is quite similar to what one would write by hand: + +static int wrapper_numel(lua_State *L) +{ + int narg = lua_gettop(L); + THDoubleTensor *arg1 = NULL; + int arg2 = 0; + if(narg == 1 + && (arg1 = luaT_toudata(L, 1, torch_DoubleTensor_id)) + ) + { + } + else + luaL_error(L, "expected arguments: DoubleTensor"); + arg2 = numel(arg1); + lua_pushnumber(L, (lua_Number)arg2); + return 1; +} + -- cgit v1.2.3