Пример #1
0
static int filefind_index_table(lua_State* L) {
	struct FileFindInfo* info = filefind_checkmetatable(L, 1);
	lua_newtable(L);
	filefind_index_filename_helper(L, info);
	lua_setfield(L, -2, "filename");
	filefind_index_creation_time_helper(L, info);
	lua_setfield(L, -2, "creation_time");
	filefind_index_access_time_helper(L, info);
	lua_setfield(L, -2, "access_time");
	filefind_index_write_time_helper(L, info);
	lua_setfield(L, -2, "write_time");
	filefind_index_creation_FILETIME_helper(L, info);
	lua_setfield(L, -2, "creation_FILETIME");
	filefind_index_access_FILETIME_helper(L, info);
	lua_setfield(L, -2, "access_FILETIME");
	filefind_index_write_FILETIME_helper(L, info);
	lua_setfield(L, -2, "write_FILETIME");
	filefind_index_size_helper(L, info);
	lua_setfield(L, -2, "size");
	filefind_index_is_directory_helper(L, info);
	lua_setfield(L, -2, "is_directory");
	filefind_index_is_readonly_helper(L, info);
	lua_setfield(L, -2, "is_readonly");
	return 1;
}
Пример #2
0
static int filefind_next(lua_State *L) {
	struct FileFindInfo* info = filefind_checkmetatable(L, 1);
	if (FileFindNextMatch(info)) {
		lua_pushvalue(L, 1);
		return 1;
	}
	return 0;
}
Пример #3
0
static int filefind_gc(lua_State *L) {
	struct FileFindInfo* info = filefind_checkmetatable(L, 1);
#if defined(WIN32)
	if (info->handle != INVALID_HANDLE_VALUE)
		FindClose(info->handle);
#else
	if (info->dirp)
		closedir(info->dirp);
	free(info->path);
	free(info->wildcard);
#endif
	return 0;
}
Пример #4
0
static int filefind_close(lua_State *L) {
	struct FileFindInfo* info = filefind_checkmetatable(L, 1);
#if defined(WIN32)
	if (info->handle) {
		FindClose(info->handle);
		info->handle = NULL;
	}
#else
	if (info->dirp) {
		closedir(info->dirp);
		info->dirp = NULL;
	}
#endif
	return 0;
}
Пример #5
0
static int filefind_index(lua_State *L) {
	lua_CFunction function;
	struct FileFindInfo* info = filefind_checkmetatable(L, 1);
	const char* key = luaL_checklstring( L, 2, NULL );
	lua_getfield( L, lua_upvalueindex( 1 ), key );
	if ( !lua_isnil( L, -1 ) )
		return 1;
	lua_getfield( L, lua_upvalueindex( 2 ), key );
	function = lua_tocfunction( L, -1 );
	if ( function )
		return function( L );
	lua_getfield( L, lua_upvalueindex( 3 ), key );
	if ( !lua_isnil( L, -1 ) )
		return 1;
    luaL_argerror(L, 2, "improper key");
	return 1;
}
Пример #6
0
static int l_filefind_attributes(lua_State* L) {
	struct FileFindInfo* info;
	l_filefind_first(L);
	info = filefind_checkmetatable(L, -1);
#if defined(_WIN32)
	if (info->handle == INVALID_HANDLE_VALUE) {
		info->handle = NULL;
		return 0;
	}
#else
	if (!info->dirp)
		return 0;
#endif
	filefind_index_table_helper(L, info, 1);
	filefind_close_helper(L, info);
	return 1;
}
Пример #7
0
static int filefind_tostring(lua_State *L) {
	struct FileFindInfo* info = filefind_checkmetatable(L, 1);
	char buffer[100];
	int top;
#if defined(_WIN32)
	if (info->handle == INVALID_HANDLE_VALUE) {
		lua_pushstring(L, "[filefind object]: empty");
		return 1;
	}

	top = lua_gettop(L);
	lua_pushstring(L, "[filefind object]: filename = \"");
	lua_pushstring(L, info->fd.cFileName);
	lua_pushstring(L, "\"");
	sprintf(buffer, ", creation_time = %u", fileglob_ConvertToTime_t(&info->fd.ftCreationTime));
	lua_pushstring(L, buffer);
	sprintf(buffer, ", access_time = %u", fileglob_ConvertToTime_t(&info->fd.ftLastAccessTime));
	lua_pushstring(L, buffer);
	sprintf(buffer, ", write_time = %u", fileglob_ConvertToTime_t(&info->fd.ftLastWriteTime));
	lua_pushstring(L, buffer);
	sprintf(buffer, ", creation_FILETIME = { %u, %u }", info->fd.ftCreationTime.dwLowDateTime, info->fd.ftCreationTime.dwHighDateTime);
	lua_pushstring(L, buffer);
	sprintf(buffer, ", access_FILETIME = { %u, %u }", info->fd.ftLastAccessTime.dwLowDateTime, info->fd.ftLastAccessTime.dwHighDateTime);
	lua_pushstring(L, buffer);
	sprintf(buffer, ", write_FILETIME = { %u, %u }", info->fd.ftLastWriteTime.dwLowDateTime, info->fd.ftLastWriteTime.dwHighDateTime);
	lua_pushstring(L, buffer);
	sprintf(buffer, ", size = %I64d", ((unsigned __int64)info->fd.nFileSizeLow + ((unsigned __int64)info->fd.nFileSizeHigh << 32)));
	lua_pushstring(L, buffer);
	sprintf(buffer, ", is_directory = %s", (info->fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0 ? "true" : "false");
	lua_pushstring(L, buffer);
	sprintf(buffer, ", is_link = %s", (info->fd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0 ? "true" : "false");
	lua_pushstring(L, buffer);
	sprintf(buffer, ", is_readonly = %s", (info->fd.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? "true" : "false");
	lua_pushstring(L, buffer);

	filefind_index_number_of_links_helper(L, info);
	sprintf(buffer, ", number_of_links = %d", lua_tointeger(L, -1));
	lua_pop(L, 1);

	lua_pushstring(L, buffer);
	lua_concat(L, lua_gettop(L) - top);
	return 1;
#else
	return 0;
#endif
}
Пример #8
0
static int filefind_index_is_readonly(lua_State* L) {
	return filefind_index_is_readonly_helper(L, filefind_checkmetatable(L, 1));
}
Пример #9
0
static int filefind_index_is_directory(lua_State* L) {
	return filefind_index_is_directory_helper(L, filefind_checkmetatable(L, 1));
}
Пример #10
0
static int filefind_index_size(lua_State* L) {
	return filefind_index_size_helper(L, filefind_checkmetatable(L, 1));
}
Пример #11
0
static int filefind_index_write_FILETIME(lua_State* L) {
	return filefind_index_write_FILETIME_helper(L, filefind_checkmetatable(L, 1));
}
Пример #12
0
static int filefind_index_access_time(lua_State* L) {
	return filefind_index_access_time_helper(L, filefind_checkmetatable(L, 1));
}
Пример #13
0
static int filefind_index_table(lua_State* L) {
	struct FileFindInfo* info = filefind_checkmetatable(L, 1);
	return filefind_index_table_helper(L, info, 1);
}
Пример #14
0
static int filefind_index_number_of_links(lua_State* L) {
	return filefind_index_number_of_links_helper(L, filefind_checkmetatable(L, 1));
}
Пример #15
0
static int filefind_index_is_link(lua_State* L) {
	return filefind_index_is_link_helper(L, filefind_checkmetatable(L, 1));
}