• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Is a lone return statement valid Lua code?

Resolved: Is a lone return statement valid Lua code?

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

In the pandoc introduction to filters the following code is presented as an “example of a Lua filter”:
I have never seen a standalone return statement in Lua as shown in the example above. Furthermore I cannot see this syntax documented anywhere in the official reference.
Could anyone please let me know the following:
  • Whether this is valid Lua?
  • Where it is documented in the Lua docs?

Answer:

Yes, this is valid Lua. Lua files or strings are called “chunks” and are basically functions and may thus contain return statements like any other function. Their arguments are accessible through the vararg ....
This is documented in the Lua 5.4 reference manual section on Chunks:

Lua handles a chunk as the body of an anonymous function with a variable number of arguments (see §3.4.11). As such, chunks can define local variables, receive arguments, and return values.


When starting a Lua file from the command line, ... will be the command line arguments. When manually loading strings or loadfileing files, you get the chunk returned as a function and can decide what you want to pass.
In fact it is considered good practice to return something from a required file rather than writing your library functions to the global namespace. return is in that case equivalent to JS export:
foo.lua:
bar.lua:

If you have better answer, please add a comment about this, thank you!

function lua pandoc
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: PostgreSQL resample 1 minute OHLCV candle data into 5 minute OHLCV candle data

27/03/2023

Resolved: How do I navigate a table without any easily accessible distinctions?

27/03/2023

Resolved: Can a pod make itself unavailable temporarily in kubernetes?

27/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.