This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
OpieThePug's profile picture

// Comment style

Started by OpieThePug, 26 August 2013 - 11:25 PM
OpieThePug #1
Posted 27 August 2013 - 01:25 AM
Title: // Comment style
Body:
Just wondering if the double forward slash comment style is available. I ran a test on a startup script and the bios failed when I inserted
//This is a test
into my code. However,
--This is a test
seemed to work fine. Maybe I'm doing something wrong, or it's because I'm using Tekkit which is still on 1.5.2. I have the latest version of CC, but I'd like to see if //-type comments can be implemented. It's drilled into my brain from years of coding for Garry's Mod, and the double forward slash is just my style. :)/> Thanks for your time.
Lyqyd #2
Posted 27 August 2013 - 10:25 AM
Nope.

Only – for line comments and –[[ … ]] for block comments.
TheOddByte #3
Posted 27 August 2013 - 01:11 PM
As Lyqyd said: Nope
But it's pretty useful to use comment blocks

--[[
Here you can put your comments
]]--

Since it's more useful than doing this if you have a lot in your comment

-- Hello
-- World
-- !
But that is useful for single line comments that are short ofcourse(But they don't need to be short :P/>)
Lyqyd #4
Posted 27 August 2013 - 01:37 PM

--[[You only need the leading double dash.]]
GopherAtl #5
Posted 27 August 2013 - 03:51 PM
it's a common convention to end with –]], because it allows you to enable/disable commented blocks of code by just adding a - before the beginning of the comment


--[[ this block of code is disabled by the comment block
print("disabled code!")
--]]

---[[ this line is still a comment but the third - makes it NOT start a block anymore
print("enabled code!")
--]]
here's what that might look like with proper syntax highlighting…


in the first block, the – before ]] is ignored as part of the comment block; in the 2nd, the – prevents the ]] from throwing a syntax error, since it has no matching [[

that's why you so often see –]] instead of just ]], which would work as well. Unless you're using an editor with proper syntax highlighting. Neither the forum nor the built-in edit program properly handle multiline lua comments, but any external editors with lua syntax highlighting should. Without proper highlighting, both of these are potentially confusing, so be careful.
OpieThePug #6
Posted 27 August 2013 - 03:52 PM
:(/> Well thanks for your help anyway.