| ------------------------------------------------------------------------------- |
| -- Copyright (c) 2006-2013 Fabien Fleutot and others. |
| -- |
| -- All rights reserved. |
| -- |
| -- This program and the accompanying materials are made available |
| -- under the terms of the Eclipse Public License v1.0 which |
| -- accompanies this distribution, and is available at |
| -- http://www.eclipse.org/legal/epl-v10.html |
| -- |
| -- This program and the accompanying materials are also made available |
| -- under the terms of the MIT public license which accompanies this |
| -- distribution, and is available at http://www.lua.org/license.html |
| -- |
| -- Contributors: |
| -- Fabien Fleutot - API and implementation |
| -- |
| ------------------------------------------------------------------------------- |
| |
| require 'metalua.dollar' |
| |
| -{ extension ('match', ...) } |
| |
| function dollar.log(...) |
| local args = {...} |
| local ti = table.insert |
| local code = { } |
| local nohash = false |
| local width = 80 |
| |
| local i=1 |
| if args[i].tag=='String' then |
| ti(code, +{print(" [LOG] "..-{args[1]})}) |
| i += 1 |
| end |
| |
| local xtra_args, names, vals = { }, { }, { } |
| for i=i, #args do |
| match args[i] with |
| | +{ 'nohash' } -> nohash = true |
| | `Number{ w } -> width = w |
| --| `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 |
| local msg = string.format(" [LOG] %s = ", names[i]) |
| local printer = `Call{ +{table.tostring}, |
| vals[i], |
| `Number{ width }, |
| `Number{ #msg } } |
| if nohash then ti(printer, +{'nohash'}) end |
| ti (code, `Call{ +{printf}, +{"%s%s"}, `String{ msg }, printer }) |
| end |
| return code |
| end |
| |
| return function() end |