title: Adding labels to my programming language
body: <p>Actually I am writting a programming language in Lua. It was quite fun. I've wrote a bit of standard library (stack op and simple io). Then I've thought about labels. It would look like in assembly. While and for loop aren't funny in any bit so programming in that language can be quite challenging. Here are some requirements for this system:</p>
  
  <ul>
  <li>Label stack (or array, dictionary) must be accessible from global context.</li>
  <li>Jump instruction handler will be in separate file.</li>
  </ul>
  
  <p>This is how my label-handling function look like:</p>
  
  <pre><code>function handleLabel(name,currentLine)
  end
  </code></pre>
  
  <p>I have no idea how to implement this kind of magic. First I've thought about that:</p>
  
  <pre><code>LabelLineIDS = {}
  Labels = {}
  Labelamount = 1;
  
  
  function handleLabel(name,currentLine)
      LabelLineIDS[Labelamount]=currentline
      Labels[Labelamount]=name
      Labelamount=Labelamount+1
  end
  
  -- In file "jump.lua":
  
  local function has_value (tab, val)
      for index, value in ipairs(tab) do
          if value == val then
              return index
          end
      end
  
      print ("Error: Label not defined.") -- Bail out.
      os.exit(1)
  end
  
  local function _onlabel()
      local labelName = globalparams --Globalparams variable contain parameters to each function, at the moment
                                     --this will contain label name. It _can_ be nil.
      return LabelLineIDS[has_value(Labels, labelName)]
  end
  CurrLine = _onlabel() --Currline - current line that get's parsed.
                       --1 command per one line.
  </code></pre>
  
  <p>But I'm unsure is this well written or even work. Can you give me idea how to parse labels in my programming language (and write jump functions)? Or if my code is pretty ok at the moment, can you help me to improve it?</p>