diff options
| author | [email protected] <[email protected]> | 2012-11-10 07:32:39 +0000 |
|---|---|---|
| committer | [email protected] <[email protected]> | 2012-11-10 07:32:39 +0000 |
| commit | c77e9d5c76edada64500fa4c38dee847992f61d7 (patch) | |
| tree | f145b9e1312059dab6002d46188a91238fec4079 /components/external/lua/test | |
| parent | 0d77b327a998c35e53025690415a3d355717eb95 (diff) | |
add lua support for rt-thead
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2399 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'components/external/lua/test')
| -rw-r--r-- | components/external/lua/test/SConscript | 11 | ||||
| -rw-r--r-- | components/external/lua/test/test.c | 53 |
2 files changed, 64 insertions, 0 deletions
diff --git a/components/external/lua/test/SConscript b/components/external/lua/test/SConscript new file mode 100644 index 0000000000..c891d565be --- /dev/null +++ b/components/external/lua/test/SConscript @@ -0,0 +1,11 @@ + +import os +from building import * + +cwd = GetCurrentDir() +src = Glob('*.c') +CPPPATH = [cwd, str(Dir('#'))] + +group = DefineGroup('lua', src, depend = ['RT_USING_LUA'], CPPPATH = CPPPATH) + +Return('group') diff --git a/components/external/lua/test/test.c b/components/external/lua/test/test.c new file mode 100644 index 0000000000..5dc46961ec --- /dev/null +++ b/components/external/lua/test/test.c @@ -0,0 +1,53 @@ + +#include "lua.h" +#include "lauxlib.h" + +#include "finsh.h" + +int c_print(lua_State *L) +{ + int n = lua_gettop(L); + int i; + + for (i=1; i<=n; i++) + { + if (i>1) + rt_kprintf("\t"); + + if (lua_isstring(L,i)) + rt_kprintf("%s",lua_tostring(L,i)); + else if (lua_isnumber(L, i)) + rt_kprintf("%d",lua_tointeger(L,i)); + else if (lua_isnil(L,i)) + rt_kprintf("%s","nil"); + else if (lua_isboolean(L,i)) + rt_kprintf("%s",lua_toboolean(L,i) ? "true" : "false"); + else + rt_kprintf("%s:%p",luaL_typename(L,i),lua_topointer(L,i)); + } + + rt_kprintf("\n"); + + return 0; +} + +/** + * lua call c function + */ +int luacprint() +{ + lua_State *L = luaL_newstate(); + lua_register(L, "c_print", c_print); + + rt_kprintf("lua test - c_print: c_print('lua for rt-thread')\n"); + luaL_dostring(L, "c_print('lua for rt-thread')"); + rt_kprintf("done\n"); + + lua_close(L); + + return 0; +} +FINSH_FUNCTION_EXPORT(luacprint, register c function in lua and call it) + + + |
