在Air2xx/8xx系列的core中添加自己的lua模块

下载core

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

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

添加模块

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

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

放入如下示例代码:

#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include <string.h>
#include <stdlib.h>
#include <ctype.h>

static int test_get( lua_State *L )
{
    int number = luaL_checkinteger( L, 1 );

    lua_pushinteger( L, number + 1);
    return 1;
}

// Module function map
#include "lrodefs.h"
const LUA_REG_TYPE test_map[] =
{
  { LSTRKEY( "get" ),  LFUNCVAL( test_get ) },
  { LNILKEY, LNILVAL }
};

LUALIB_API int luaopen_test( lua_State *L )
{
  luaL_register( L, AUXLIB_TEST, test_map );

  return 1;
}

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

在合适位置加上:

#define AUXLIB_TEST  "test"
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运行版本\目录找到

测试

1 Comment

文娱帝国进行回复 取消回复

您的电子邮箱地址不会被公开。