0

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 )
3
  • 4
    concommand is an object that doesn't exist. Where is it defined? Commented Jan 8, 2014 at 5:55
  • Isnt it a predefined object in lua ? I am a beginner in lua , and got this code from here wiremod.com/forum/wiremod-addons-coding/… Commented Jan 8, 2014 at 6:01
  • Just from Googling it, it looks like it's part of some Valve mod library. Commented Jan 8, 2014 at 6:23

2 Answers 2

2

I was unable to follow your wiremod link (need login to download). But looks like this script is supposed to be run from within some application that embeds Lua to make itself scriptable (I think gmod http://www.garrysmod.com/). You can't just run the script on its own: several of the variables you see in this script are linked to data in the host application.

To create a web browser iike the script does, you will have to install that application. Alternately, drop this approach and start with something simpler and more fun, like Corona which uses Lua, it will be much better documented and have more community support.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your answer. Well yes, on wiremod it says "Put web_browser.lua in lua/autorun/ It can be installed on server and client. Type OpenWebBrowser in console to use. " I have no idea where to put it. Actually I was looking to add the lua web browser as vlc extension. Not sure it will work using Corona.
@user2681573 That lua/autorun path you gave is where you need to put it. Where that path is exactly I don't know but presumably the documentation for Garry's Mod will tell you.
@user2681573 That .lua will not work with corona, I was suggesting to try something that has better docs and easier to learn.
0

That script is from 2010, while Garry made some API changes to Garry's Mod in 2012/13. It's unlikely that the script will work as-is.

Also, I would agree with Schollii to not start programming with Garry's Mod. The API is not very good.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.