Skip to content

coderofsalvation/meta.awk.lua

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Metaprogramming code-generators in ~700 bytes

▓▓▓ ▒▒▒ ▒▒▒ ▓▓▓ ███

███ ▓▓▓ ▒▒▒ ▓▓▓ ███

▓▓▓ ███ ▓▓▓ ▒▒▒ ▓▓▓

▒▒▒ ▓▓▓ ███ ▓▓▓ ▒▒▒ awk metaprogrammer 

Tiny scripts, huge potential. #preprocessor #awk #lua #permacomputing #lite

Usage (Basic templates)

NOTE: meta.awk and meta.lua are interchangable. For exotic operating systems without lua/awk: check here

$ ./meta.awk input.html > output.html
$ ./meta.lua input.html > output.html
<ul>
# for( i = 0; i < 2; i++ ){
  <li>
#   print("   "i) 
  </li>
# }
</ul>

output.html:

<ul>
  <li>
   0
  </li>
  <li>
   1
  </li>
</ul>

Multilanguage preprocessor

You can change the prefix (#) to fit other languages better. Here's a 3-in-1 demo which generates nelua/redbean-specific code from lua-code:

$ target=redbean meta.lua input.lua '--|' > out.redbean.lua
$ target=nelua   meta.lua input.lua '--|' > out.nelua 
$ target=lua     meta.lua input.lua '--|' > out.lua 

input.lua:

--| target = os.getenv("target")
--| if target == "nelua" then
local a: Person =
--| else
local a =
--| end
{name = "Mark", age = 20}

--| if target ~= "redbean" then
function LaunchBrowser() return false; end  -- dummy function
--| end

print(a.name, a.age)
print("hello world from $(target)")

out.nelua:

local a: Person =
{name = "Mark", age = 20}
function LaunchBrowser() return false; end  -- dummy function

print(a.name, a.age)
print("hello world from nelua")

out.redbean.lua:

local a =
{name = "Mark", age = 20}

print(a.name, a.age)
print("hello world from redbean")

out.lua:

local a =
{name = "Mark", age = 20}
function LaunchBrowser() return false; end  -- dummy function

print(a.name, a.age)
print("hello world from lua")

Portable binaries

Chances are your OS already has lua/awk installed. However:

TIP: see portable crossplatform awk/lua binaries thanks to cosmopolitan libc♥) (don't forget to run chmod +x awk lua)

Why

AWK is awesome, its tiny and usually preinstalled on many Os'ses..linux distros..busybox..etc Lua is awesome, and tiny and has various cool dialects (teal / nelua) allow targeting web/games/esp32 from the same lua-code.

About

Metaprogramming code-generators in ~700 bytes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors