Air724C_SDK
在lua里调用CSDK里的函数步骤
-
首先需要在\app\elua\modules\include\
auxmods.h
中声明模块名字和模块初始化函数1 2
#define AUXLIB_XUEHU "xuehu" LUALIB_API int ( luaopen_xuehu )( lua_State *L );
-
在app\elua\platform\openat\include\
platform_conf.h
文件中完成将模块名和初始化函数注册到lua内核中1
_ROM( AUXLIB_XUEHU, luaopen_xuehu, xuehu_map ) \
-
注册有哪些函数
app\elua\modules\src新建xuehu.c
cmakelist添加
src/xuehu.c
xuehu.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
// Module for interfacing with Xuehu #include "lua.h" #include "lualib.h" #include "lauxlib.h" #include "lplatform.h" #include "auxmods.h" #include "lrotable.h" #include "platform_conf.h" #include <stdio.h> #include <string.h> #include <ctype.h> // Lua: num = xuehu.getnum( num ) static int xuehu_getnum( lua_State* L ) { int pin; pin = luaL_checkinteger( L, 1 ); lua_pushinteger( L, pin+30 ); return 1; } #define MIN_OPT_LEVEL 2 #include "lrodefs.h" static const LUA_REG_TYPE xuehu_map[] = { /*lua中函数名 c语言函数名*/ { LSTRKEY( "getnum" ), LFUNCVAL ( xuehu_getnum ) }, { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_xuehu( lua_State *L ) { #if LUA_OPTIMIZE_MEMORY > 0 return 0; #else // #if LUA_OPTIMIZE_MEMORY > 0 luaL_register( L, AUXLIB_XUEHU, xuehu_map ); return 1; #endif // #if LUA_OPTIMIZE_MEMORY > 0 }
- 原文作者:xuehu
- 原文链接:https://www.xuehu96.com/post/air724csdk/
- 版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可,非商业转载请注明出处(作者,原文链接),商业转载请联系作者获得授权。