Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wxDir:Exists and wxDir:GetAllFiles compile but fail at runtime #66

Closed
decuant opened this issue Apr 30, 2020 · 1 comment
Closed

wxDir:Exists and wxDir:GetAllFiles compile but fail at runtime #66

decuant opened this issue Apr 30, 2020 · 1 comment
Assignees

Comments

@decuant
Copy link

decuant commented Apr 30, 2020

Hello,

I'm using wxDir and I'm getting this strange error with Exists and GetAllFiles.

C:\Program Files (x86)\ZeroBrane\bin\lua53.exe: C:\USR_2\LUA\WMOQuery\compile.lua:65: wxLua: Expected a 'string' or 'wxString' for parameter 1, but got a 'userdata'.

Function called: 'GetAllFiles(wxDir, string, number)'
01. wxDir::GetAllFiles(string [, string, number]) - static
stack traceback:
	[C]: in method 'GetAllFiles'

I reverted my source code to use Open instead of Exists and GetFirst/GetNext instead of GetAllFiles, but wanted to point the issue out.

Below is code failing (actually lines commented out), if can be of help:

local function ProcessDirectory(inPathname)
	trace.newLine("ProcessDirectory [" .. inPathname .. "]")
	
	local dir = wx.wxDir()
	
	if not dir:Open(inPathname) then
		
		trace.line("Cannot open directory [" .. inPathname .. "]")
		return
	end
	
--	local _, tFilenames = dir:GetAllFiles("*.json", wx.wxDIR_FILES) 
	
--	if tFilenames then
		
--		for _, sFilename in ipairs(tFilenames) do
			
--			ProcessFile(sFilename)
--		end
--	end
	
--	local _, tDirectories = dir:GetAllFiles("*.*", wx.wxDIR_DIRS)
	
--	if tDirectories then
		
--		for _, sDirectory in ipairs(tDirectories) do
			
--			ProcessDirectory(sDirectory)
--		end
--	end

	local _, sFilename = dir:GetFirst("*.json", wx.wxDIR_FILES)
	
	while sFilename and 0 < #sFilename do
		
		ProcessFile(inPathname .. "\\" .. sFilename)
		
		_, sFilename = dir:GetNext()
	end
	
	local _, sDirectory = dir:GetFirst("*", wx.wxDIR_DIRS)
	
	while sDirectory and 0 < #sDirectory do
		
		ProcessDirectory(inPathname .. "\\" .. sDirectory)
		
		_, sDirectory = dir:GetNext()
	end

	dir:Close()
end

Thank you

Antonio

@pkulchenko pkulchenko self-assigned this May 1, 2020
@pkulchenko
Copy link
Owner

@decuant, both Exists and GetAllFiles are static functions, so you'd need to call them as wxDir.Exists() or dir.Exists() (assuming dir = wx.wxDir()). Notice . instead of :, as the static functions are not methods, so they don't take the object as the first parameter.

Also, for GetAllFiles, it expects the path, the filespec, and the flags, so in your case the call should be dir.GetAllFiles(inPathname, "*.json", wx.wxDIR_FILES). The directory referenced by dir doesn't need to be open for these methods to work, as they take the directory name as the parameter.

  1. wxDir::GetAllFiles(string [, string, number]) - static

Notice that it references the fact that the function is static in the description, although it's easy to miss.

I'm closing this, but let me know if this still doesn't work for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants