Lua: Derma Forward Declarations

Here’s my code:
local DermaTextPath = vgui.Create( “DTextEntry”, DermaPanel)
DermaTextPath:SetValue( “Enter a directory within the garrysmod/garrysmod/data folder” )
DermaTextPath:SetPos( 25, 25 )
DermaTextPath:SetWide( 510 )
DermaTextPath:SetTall( 20 )
DermaTextPath:SetEnterAllowed( true )
function DermaTextPath:OnEnter()
path = DermaTextPath:GetValue() … “*”

local DermaListView = vgui.Create( "DListView", DermaPanel )
DermaListView:SetPos( 25, 100 )
DermaListView:SetSize( 550, 625 )
DermaListView:SetMultiSelect( false )
DermaListView:AddColumn( "Name" )
DermaListView.BuildListBox = function( self )
	for k,v in pairs(file.Find(path)) do
end -- For the below stuff don't forget to test everything with backslash (\)
DermaListView.DoDoubleClick = function( parent, index, list, PathSections )
	path = path .. list:GetValue(1)
	path = string.gsub( path, "*", "" )
	if file.Size( path ) == -1 then
		path = path .. "/"
		DermaTextPath:SetValue( path )
		path = path .. "*"
		Msg( file.Read( path ) )
		DermaPanel:SetVisible( false )


So the problem with this is that the DermaListView.DoDoubleClick function involves the DermaTextPath and the DermaTextPath.OnEnter function requires the DermaListView. The compiler gives me an error in DermaTextPath that it doesn’t know what DermaListView is because since DermaTextPath is above it DermaListView hasn’t been defined yet.

Based on my knowledge of C++ I think I need to use forward declaration to fix this but I’m not sure how to do that in Lua, and I’m not sure how to do that for Derma elements. Is there a way I can forward declare DermaListView so that I can make this work?

Just move DermaTextPath:OnEnter() to somewhere below where you define DermaListView.

Oh yeah that’s a good idea. Thanks.

If you’d rather “forward declarate” it you can put
local DermaListView
Before the DermaTextPath declaration, and remove the local where you are defining DermaListView.

You would probably need a dummy function instead, to prevent errors due to calling the variable, so replace that with “local DermaListView = function() end” or something.

You are confused, go to sleep:colbert:

Thanks everyone but I think I’ll use the first solution.