How to exit a Lua script's execution?

lua

Solution

extract from the lua api doc :

For syntactic reasons, a break or return can appear only as the last statement of a block (in other words, as the last statement in your chunk or just before an end, an else, or an until). For instance, in the next example, break is the last statement of the then block.

local i = 1
while a[i] do
  if a[i] == v then break end
  i = i + 1
end

Usually, these are the places where we use these statements, because any other statement following them is unreachable. Sometimes, however, it may be useful to write a return (or a break) in the middle of a block; for instance, if you are debugging a function and want to avoid its execution. In such cases, you can use an explicit do block around the statement:

function foo ()
  return          --<< SYNTAX ERROR
  -- `return' is the last statement in the next block
  do return end   -- OK
  ...             -- statements not reached
end

Problem

I want to exit the execution of a Lua script on some condition. For example: ``` content = get_content() if not content then -- ( Here i want some kind of exit function ) next_content = get_content() --example there can lot of further checks ``` Here I want that if I am not getting content my script suppose to terminate is should not go to check to next.

Original source