[NTG-context] Learning LuaTeX : Invoice

Wolfgang Schuster schuster.wolfgang at googlemail.com
Sun Feb 20 13:08:43 CET 2011


Am 20.02.2011 um 12:55 schrieb Henning Hraban Ramm:

> Maybe similar to the "spreadsheet" question:
> I'm trying to use Wolfgang's letter module for my invoices and would like to use Lua for the sums.
> But I fail already at the beginning:
> 
> \startluacode
> userdata = userdata or {}
> 
> userdata.invoice = userdata.invoice or { sum = 0 } -- global table for sums
> 
> function userdata.singlesum(hours, perhour)
> 	amount = hours * perhour
> 	userdata.invoice.sum = userdata.invoice.sum + amount
> 	global.context(string.gsub(string.format("\%.2f", amount), "%.", ","))
> 	return amount
> end
> 
> \stopluacode

\startluacode

userdata = userdata or {}

userdata.invoice = userdata.invoice or { sum = 0 } -- global table for sums

function userdata.singlesum(hours, perhour)
	local amount = hours * perhour
	userdata.invoice.sum = userdata.invoice.sum + amount
 	context(string.gsub(string.format("%.2f",amount),"%.",","))
end

\stopluacode

\starttext
\ctxlua{userdata.singlesum(3,4)}
\stoptext

Wolfgang



More information about the ntg-context mailing list