在core中添加自己的lua模块

# 下载core 打开[http://www.openluat.com/Product/gprs/Air202.html](http://www.openluat.com/Product/gprs/Air202.html)--> 资料下载 --> 下载源码 ![](/static/editormd/php/../uploads/5...

下载core

打开http://www.openluat.com/Product/gprs/Air202.html—> 资料下载 —> 下载源码

把压缩包里的文件解压到一个位置

添加模块

假设新增的模块叫test,调用test.get(a)返回a+1后的值

core\cust_src\elua\modules\src新建一个文件test.c

放入如下示例代码:

  1. #include "lua.h"
  2. #include "lualib.h"
  3. #include "lauxlib.h"
  4. #include "platform.h"
  5. #include "auxmods.h"
  6. #include "lrotable.h"
  7. #include <string.h>
  8. #include <stdlib.h>
  9. #include <ctype.h>
  10. static int test_get( lua_State *L )
  11. {
  12. int number = luaL_checkinteger( L, 1 );
  13. lua_pushinteger( L, number + 1);
  14. return 1;
  15. }
  16. // Module function map
  17. #include "lrodefs.h"
  18. const LUA_REG_TYPE test_map[] =
  19. {
  20. { LSTRKEY( "get" ), LFUNCVAL( test_get ) },
  21. { LNILKEY, LNILVAL }
  22. };
  23. LUALIB_API int luaopen_test( lua_State *L )
  24. {
  25. luaL_register( L, AUXLIB_TEST, test_map );
  26. return 1;
  27. }

接着,打开文件core\cust_src\elua\modules\include\auxmods.h

在合适位置加上:

  1. #define AUXLIB_TEST "test"
  2. LUALIB_API int ( luaopen_test )( lua_State *L );

打开core\cust_src\elua\platform\coolsand\include\platform_conf.h
在合适位置加上_ROM( AUXLIB_TEST, luaopen_test, test_map ) \

编译

下载csdtk4,解压到c盘根目录:
https://1dv.papapoi.com/%E8%BD%AF%E4%BB%B6/csdk%E7%9B%B8%E5%85%B3/CSDTK4.7z

运行core\project\你需要的lua运行版本\build\ cust_build.bat编译即可
运行core\project\你需要的lua运行版本\build\ cust_clean.bat可完全重新编译
Lod文件可在core\hex\你需要的lua运行版本\目录找到

测试

  • 发表于 2019-01-28 11:57
  • 阅读 ( 4061 )
  • 分类:默认分类

1 条评论

请先 登录 后评论
不写代码的码农
晨旭

菜鸟

20 篇文章

作家榜 »

  1. 技术销售Delectate 43 文章
  2. 陈夏 26 文章
  3. 国梁 24 文章
  4. miuser 21 文章
  5. 晨旭 20 文章
  6. 朱天华 19 文章
  7. 金艺 19 文章
  8. 杨奉武 18 文章