0

is there a way to define {} and blankspace as a lua code block?

something like this..

function()
{
   local x = 3
   if     (x == 1) { print("hi1") }
   elseif (x == 2)   print("hi2") 
   else   (x == 3)   print("hi3") 
}

it would also be nice to define things like ++ and += too

Shadowblitz16
  • 137
  • 2
  • 11
  • 2
    There exist a lot of languages with almost-C syntax. But in Lua `--` means "start of a single-line comment", and `{..}` is used for a table constructor. – Egor Skriptunoff Jan 23 '19 at 07:43
  • If you want to experiment with alternative syntax for Lua, try [ltokenp](http://webserver2.tecgraf.puc-rio.br/~lhf/ftp/lua/index.html#ltokenp). – lhf Jan 23 '19 at 11:13
  • I believe the answer to another question explains why lua does not have `+=` well https://stackoverflow.com/questions/20091779/lua-operators-why-isnt-and-so-on-defined?answertab=oldest#tab-top – Nifim Jan 23 '19 at 17:19

1 Answers1

0

Just use do..end. += operator and friends aren't conformant with spirit of Lua. Your code will not run. First of all, you need to understand basic Lua syntax. Example of corrected code:

function f()
   local x = 3
   if x == 1 then
      print("hi1")
   elseif x == 2 then
      print("hi2")
   elseif x == 3 then
      print("hi3")
   end
end

To create block simply use

do
  print('Hello, world!')
end

You can check out Lua manual here, whenever you run to trouble.

Kamila Szewczyk
  • 1,874
  • 1
  • 16
  • 33
  • I wanted to use some sort of macros to make it look more like c i know there are a few macro libraries that can achieve += and {} i just don't know how to use them. – Shadowblitz16 Feb 02 '19 at 23:00