I want to make a simple web browser in lua. I got the following script. But its not compiling and giving error : attempt to index global 'concommand' (a nil value) Can anyone tell whats wrong with my script?
-- Simple Web Browser by Drunkie
if SERVER then AddCSLuaFile("web_browser.lua") return end
concommand.Add( "OpenWebBrowser", function()
local homepage = "http://www.google.com"
local frame = vgui.Create( "DFrame" )
frame:SetSize( ScrW()*0.8, ScrH()*0.8 )
frame:SetTitle( "" )
frame:SetDraggable( false )
frame:Center()
frame:MakePopup()
frame.Paint = function()
surface.SetDrawColor( 0, 0, 0, 150 )
surface.DrawRect( 0, 0, frame:GetWide(), frame:GetTall() )
end
local lbl_loading = vgui.Create( "DLabel", frame )
lbl_loading:SetText( "Loading . . ." )
surface.CreateFont( "coolvetica", 64, 400, true, false, "LoadFont" )
lbl_loading:SetFont( "LoadFont" )
lbl_loading:SetColor( Color( 255, 255, 255 ) )
lbl_loading:SizeToContents()
lbl_loading:Center()
local html_pos = { 12, 48 }
local html_size = { frame:GetWide()-html_pos[1]*2, frame:GetTall()-html_pos[2]-html_pos[1] }
local html_frame = vgui.Create( "HTML", frame )
html_frame:SetPos( html_pos[1], html_pos[2] )
html_frame:SetSize( html_size[1], html_size[2] )
html_frame:OpenURL( homepage )
local lbl_goto = vgui.Create( "DLabel", frame )
lbl_goto:SetText( "Goto:" )
surface.CreateFont( "coolvetica", 24, 400, true, false, "GotoFont" )
lbl_goto:SetFont( "GotoFont" )
lbl_goto:SetColor( Color( 255, 255, 255 ) )
lbl_goto:SetPos( 12, 16 )
lbl_goto:SizeToContents()
local txt_goto = vgui.Create( "DTextEntry", frame )
txt_goto:SetSize( frame:GetWide()-96, 24 )
txt_goto:SetPos( 64, 14 )
txt_goto:SetText( homepage )
txt_goto.OnEnter = function()
local site = string.lower( txt_goto:GetValue() )
-- if string.Left( site, 7 ) != "http://" then
-- site = "http://" .. site
-- txt_goto:SetText( site )
-- end
html_frame:OpenURL( site )
end
end )
concommandis an object that doesn't exist. Where is it defined?