diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2017-10-19 17:00:10 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2017-10-19 17:00:10 -0700 |
| commit | b98059261c173dab8d919e7f9a93d44c5de0329d (patch) | |
| tree | b7fdbfe9c746dc2f52a25e0dd2715c769a371d8c /examples | |
| parent | 443f8c73bb67e2fb085c5595add10b98f4696805 (diff) | |
Abbreviated "lua code" to "lua>" and "lua expr" to "=lua" and "lua
block" to "lua do>"
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/how_do_i.nom | 8 | ||||
| -rw-r--r-- | examples/sample_code.nom | 12 | ||||
| -rw-r--r-- | examples/sample_game.nom | 14 |
3 files changed, 16 insertions, 18 deletions
diff --git a/examples/how_do_i.nom b/examples/how_do_i.nom index 2365627..78a11e2 100644 --- a/examples/how_do_i.nom +++ b/examples/how_do_i.nom @@ -246,17 +246,17 @@ say both (..) # Macros: -# The "lua block %" and "lua expr %" macros can be used to write raw lua code: +# The "lua> %" and "=lua %" macros can be used to write raw lua code: rule [say the time] =: - lua block ".." + lua> ".." |nomsu:writeln("The OS time is: "..os.time()); say the time -say "Math expression result is: \(lua expr "(1 + 2*3 + 3*4)^2")" +say "Math expression result is: \(=lua "(1 + 2*3 + 3*4)^2")" #.. In the lua environment, "vars" can be used to get local variables/function args, and "nomsu" can be used to access the compiler, function defs, and other things rule [square root of %n] =: - lua expr "math.sqrt(vars.n)" + =lua "math.sqrt(vars.n)" say "The square root of 2 is \(square root of 2)" # Macros can be defined to transform one bit of nomsu code into another using "parse % as %": diff --git a/examples/sample_code.nom b/examples/sample_code.nom index 1e1ccc6..08f2af5 100644 --- a/examples/sample_code.nom +++ b/examples/sample_code.nom @@ -131,14 +131,12 @@ say ".." | and an interpolated expression: \2 + 5\ rule [%n bottles] =: - lua block ".." - |do - | print("running raw lua code...") - | for i=\(%n),1,-1 do - | print(tostring(i).." bottles of beer on the wall. Take one down, pass it around,") - | end - | print("no more bottles of beer on the wall.") + lua do> ".." + |print("running raw lua code...") + |for i=\(%n),1,-1 do + | print(tostring(i).." bottles of beer on the wall. Take one down, pass it around,") |end + |print("no more bottles of beer on the wall.") nil 9 bottles diff --git a/examples/sample_game.nom b/examples/sample_game.nom index a6a792d..d740655 100644 --- a/examples/sample_game.nom +++ b/examples/sample_game.nom @@ -6,15 +6,15 @@ require "lib/plurals.nom" # Users: with secrets: secret %users = (..) - lua expr ".." + =lua ".." |setmetatable({}, {__index={ | by_name=function(self, key) return "User<"..key..">"; end, | add=function(self, key) self[key] = self:by_name(key); end, |}}) rule [find user %name, @%name] =: - lua expr "secrets.users:by_name(vars.name) or nomsu:error('Failed to find user: '..tostring(vars.name))" + =lua "secrets.users:by_name(vars.name) or nomsu:error('Failed to find user: '..tostring(vars.name))" rule [add user %name] =: - lua expr "secrets.users:add(vars.name)" + =lua "secrets.users:add(vars.name)" rule [everybody, everyone] =: (%entry's "key") for %entry in (entries in (secret %users)) @@ -23,7 +23,7 @@ with secrets: # Inventory: with secrets: secret %inventory = (..) - lua expr ".." + =lua ".." |setmetatable({}, {__index=function(self,key) | local t = setmetatable({}, {__index=function() return 0; end}); | self[key] = t; @@ -69,14 +69,14 @@ with secrets: "inventory", "%'s inventory", "%'s stock of %", "%'s stock of % as str" rule [you] =: - lua expr "(nomsu.you or 'Anonymous')" + =lua "(nomsu.you or 'Anonymous')" rule [make %person %action, make %person do %action] =: - lua code ".." + lua> ".." |local old_you = nomsu.you |nomsu.you = vars.person do %action - lua code ".." + lua> ".." |nomsu.you = old_you say "====================================================" |
