]> git.lizzy.rs Git - metalua.git/commitdiff
added log extension
authorFabien Fleutot <fabien@macfabien.local>
Thu, 24 Jan 2008 08:30:53 +0000 (09:30 +0100)
committerFabien Fleutot <fabien@macfabien.local>
Thu, 24 Jan 2008 08:30:53 +0000 (09:30 +0100)
src/lib/extension-compiler/log.mlua [new file with mode: 0644]
src/lib/extension-runtime/log.lua [new file with mode: 0644]

diff --git a/src/lib/extension-compiler/log.mlua b/src/lib/extension-compiler/log.mlua
new file mode 100644 (file)
index 0000000..9997eb9
--- /dev/null
@@ -0,0 +1,34 @@
+require 'dollar'
+   
+-{ extension 'match' }
+
+function mlp.macros.log(...)
+   local args = {...}
+   local ti   = table.insert
+   local code = { }
+
+   local i=1
+   if args[i].tag=='String' then 
+      ti(code, +{print(-{args[1]})}) 
+      i += 1
+   end
+
+   local xtra_args, names, vals = { }, { }, { }
+   for i=i, #args do
+      match args[i] with 
+      | `String{...} | `Number{...} -> ti (xtra_args, args[i])
+      | `Id{n} -> ti (names, n); ti (vals, args[i])
+      | x      -> ti (names, table.tostring(x, 'nohash')); ti (vals, x)
+      end
+   end
+
+   for i=1, #names do
+      ti (code, `Call{ +{printf}, 
+                       +{" ** %s: ** \n%s"}, 
+                       `String{ names[i] }, 
+                       `Call{ +{table.tostring},
+                              vals[i],
+                              unpack(xtra_args) } })
+   end
+   return code
+end
diff --git a/src/lib/extension-runtime/log.lua b/src/lib/extension-runtime/log.lua
new file mode 100644 (file)
index 0000000..45b2af7
--- /dev/null
@@ -0,0 +1 @@
+do end