lua linux获取文件夹,lua 获取指定目录下指定后缀文件名

本文介绍了一种使用Lua实现的简单方法来获取Linux目录下指定后缀的文件名,通过编译的C库实现。文章还提到了lua-lfs库的不便之处,并分享了编译和使用自定义lua库的代码示例,同时提到学习Makefile的重要性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

lfs库是很好的选择,可惜不会编译,无奈只能自己写个简单的lua库。代码如下:

#include

#include

#include "lua.h"

#include "lauxlib.h"

#include "lualib.h"

static int

DirFiles(lua_State *L){

long Handle;

struct _finddata_t FileInfo;

size_t l;

int index = ;

const char* path = luaL_checklstring(L, , &l);

lua_newtable(L);

if ((Handle = _findfirst(path, &FileInfo)) != -1L)

{

lua_pushstring(L, FileInfo.name);

lua_seti(L, -, ++index);

while(_findnext(Handle, &FileInfo) == )

{

lua_pushstring(L, FileInfo.name);

lua_seti(L, -, ++index);

}

_findclose(Handle);

}

return ;

}

int

luaopen_lfs(lua_State *L){

luaL_checkver

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值