Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
AdRainty
rt-thread
提交
b41fe975
R
rt-thread
项目概览
AdRainty
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b41fe975
编写于
8月 12, 2016
作者:
B
Bernard Xiong
提交者:
GitHub
8月 12, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #654 from wuji2015/master
[lua] 增加rt_strnlen,lua采用单独的线程
上级
b59b6639
c9591f82
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
100 addition
and
20 deletion
+100
-20
components/external/lua/applications/lua_in_finsh.c
components/external/lua/applications/lua_in_finsh.c
+81
-20
src/kservice.c
src/kservice.c
+19
-0
未找到文件。
components/external/lua/applications/lua_in_finsh.c
浏览文件 @
b41fe975
...
...
@@ -20,8 +20,12 @@ rt_err_t lua_rx_ind(rt_device_t dev, rt_size_t size)
return
RT_EOK
;
}
struct
para
{
int
argc
;
char
*
argv
[
3
];
};
void
finsh_lua
(
int
argc
,
char
**
argv
)
void
finsh_lua
(
struct
para
*
parameters
)
{
rt_err_t
(
*
rx_indicate
)(
rt_device_t
dev
,
rt_size_t
size
);
...
...
@@ -34,9 +38,18 @@ void finsh_lua(int argc, char **argv)
rt_device_set_rx_indicate
(
dev4lua
.
device
,
lua_rx_ind
);
{
int
argc
=
parameters
->
argc
;
char
**
argv
=
parameters
->
argv
;
/*
rt_kprintf("argc =%d, argv[1] =%d\n", argc, argv[1]);
while(1);
*/
/* run lua interpreter */
lua_main
(
argc
,
argv
);
}
if
(
parameters
->
argc
>
1
)
rt_free
(
parameters
->
argv
[
1
]);
rt_free
(
parameters
);
/* recover old rx_indicate */
rt_device_set_rx_indicate
(
dev4lua
.
device
,
rx_indicate
);
...
...
@@ -44,6 +57,7 @@ void finsh_lua(int argc, char **argv)
static
void
lua
(
void
*
parameters
)
{
rt_thread_t
lua_thread
;
const
char
*
device_name
=
finsh_get_device
();
rt_device_t
device
=
rt_device_find
(
device_name
);
if
(
device
==
RT_NULL
)
...
...
@@ -52,29 +66,49 @@ static void lua(void *parameters)
return
;
}
dev4lua
.
device
=
device
;
char
*
argv
[]
=
{
"lua"
,
parameters
,
NULL
};
#if 0
/*prepare parameters*/
struct
para
*
lua_parameters
=
rt_malloc
(
sizeof
(
struct
para
));
if
(
lua_parameters
==
NULL
){
rt_kprintf
(
"malloc failed at file: %s,line: %d"
,
__FILE__
,
__LINE__
);
return
;
}
lua_parameters
->
argc
=
2
;
char
**
arg
=
lua_parameters
->
argv
;
arg
[
0
]
=
"lua"
;
if
(
parameters
!=
NULL
){
rt_size_t
len
=
strnlen
(
parameters
,
50
);
arg
[
1
]
=
rt_malloc
(
len
+
1
);
if
(
arg
[
1
]
==
NULL
){
rt_kprintf
(
"malloc failed at file: %s,line: %d"
,
__FILE__
,
__LINE__
);
return
;
}
rt_memset
(
arg
[
1
],
0
,
len
+
1
);
strncpy
(
arg
[
1
],
parameters
,
len
);
}
else
{
arg
[
1
]
=
NULL
;
}
arg
[
2
]
=
NULL
;
/* Run lua interpreter in separate thread */
lua_thread
=
rt_thread_create
(
"lua"
,
finsh_lua,
0
,
2048
,
(
void
(
*
)(
void
*
))
finsh_lua
,
(
void
*
)
lua_parameters
,
10240
,
rt_thread_self
()
->
current_priority
+
1
,
20
);
if
(
lua_thread
!=
RT_NULL
)
{
rt_thread_startup
(
lua_thread
);
}
#else
/* Directly run lua interpreter in finsh */
finsh_lua
(
2
,
argv
);
#endif
return
;
}
FINSH_FUNCTION_EXPORT
(
lua
,
lua
interpreter
);
static
void
lua_msh
(
int
argc
,
char
**
argv
)
{
rt_thread_t
lua_thread
;
const
char
*
device_name
=
finsh_get_device
();
rt_device_t
device
=
rt_device_find
(
device_name
);
if
(
device
==
RT_NULL
)
...
...
@@ -85,15 +119,42 @@ static void lua_msh(int argc, char **argv)
dev4lua
.
device
=
device
;
/*prepare parameters*/
int
i
;
char
**
arg
=
rt_malloc
((
argc
+
1
)
*
sizeof
(
char
*
));
for
(
i
=
0
;
i
<
argc
;
i
++
){
arg
[
i
]
=
argv
[
i
]
;
struct
para
*
parameters
=
rt_malloc
(
sizeof
(
struct
para
))
;
if
(
parameters
==
NULL
){
rt_kprintf
(
"malloc failed at file: %s,line: %d"
,
__FILE__
,
__LINE__
);
return
;
}
arg
[
argc
]
=
NULL
;
//parameters->argc = 2;
parameters
->
argc
=
argc
;
char
**
arg
=
parameters
->
argv
;
finsh_lua
(
argc
,
arg
);
rt_free
(
arg
);
arg
[
0
]
=
"lua"
;
if
(
argc
>
1
){
rt_size_t
len
=
strnlen
(
argv
[
1
],
50
);
arg
[
1
]
=
rt_malloc
(
len
+
1
);
if
(
arg
[
1
]
==
NULL
){
rt_kprintf
(
"malloc failed at file: %s,line: %d"
,
__FILE__
,
__LINE__
);
return
;
}
rt_memset
(
arg
[
1
],
0
,
len
+
1
);
strncpy
(
arg
[
1
],
argv
[
1
],
len
);
}
else
{
arg
[
1
]
=
NULL
;
}
arg
[
2
]
=
NULL
;
/* Run lua interpreter in separate thread */
lua_thread
=
rt_thread_create
(
"lua_msh"
,
(
void
(
*
)(
void
*
))(
finsh_lua
),
(
void
*
)
parameters
,
10240
,
rt_thread_self
()
->
current_priority
+
1
,
20
);
if
(
lua_thread
!=
RT_NULL
)
{
rt_thread_startup
(
lua_thread
);
}
return
;
}
MSH_CMD_EXPORT
(
lua_msh
,
lua
in
msh
);
...
...
src/kservice.c
浏览文件 @
b41fe975
...
...
@@ -462,7 +462,26 @@ rt_int32_t rt_strcmp(const char *cs, const char *ct)
return
(
*
cs
-
*
ct
);
}
RTM_EXPORT
(
rt_strcmp
);
/**
* The strnlen() function returns the number of characters in the
* string pointed to by s, excluding the terminating null byte ('\0'),
* but at most maxlen. In doing this, strnlen() looks only at the
* first maxlen characters in the string pointed to by s and never
* beyond s+maxlen.
*
* @param s the string
* @param maxlen the max size
* @return the length of string
*/
rt_size_t
rt_strnlen
(
const
char
*
s
,
rt_ubase_t
maxlen
)
{
const
char
*
sc
;
for
(
sc
=
s
;
*
sc
!=
'\0'
&&
sc
-
s
<
maxlen
;
++
sc
)
/* nothing */
;
return
sc
-
s
;
}
/**
* This function will return the length of a string, which terminate will
* null character.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录