Modulinos: Difference between revisions

Content added Content deleted
(Added newLISP)
(Added Lua)
Line 1: Line 1:
{{task|Basic language learning}}[[Category: UNIX Shell]]
{{task|Basic language learning}}[[Category: UNIX Shell]]
It is useful to be able to execute a main() function only when a program is run directly. This is a central feature in programming scripts; the feature is called /scripted main/.
It is useful to be able to execute a main() function only when a program is run directly. This is a central feature in programming scripts; the feature is called ''scripted main''.


Examples from [https://github.com/mcandre/scriptedmain GitHub].
Examples from [https://github.com/mcandre/scriptedmain GitHub].
Line 157: Line 157:
}
}
}</lang>
}</lang>

=={{header|newLISP}}==
Lua has scripted main by default, using an obscure syntax (an ellipsis of all things).

<lang lua>#!/usr/bin/env lua

os = require("os")

function main(arg)
print("Directory: " .. os.execute("pwd"))

print("Program: " .. debug.getinfo(1).source)

print("Number of Args: " .. #arg)

for i,a in ipairs(arg) do
print("Arg: " .. a)
end

end

if type(package.loaded[(...)]) ~= "userdata" then
main(arg)
else
module(..., package.seeall)
end</lang>


=={{header|newLISP}}==
=={{header|newLISP}}==