LuaPreprocess - straightforward preprocessor with simple syntax

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
yetneverdone
Party member
Posts: 391
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Re: LuaPreprocess - straightforward preprocessor with simple syntax

Post by yetneverdone »

I've noticed that a syntax error in a handler.lua file does throw an error but not detailed enough? Like there is no line number where the syntax error is.
User avatar
ReFreezed
Party member
Posts: 298
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: LuaPreprocess - straightforward preprocessor with simple syntax

Post by ReFreezed »

yetneverdone wrote: Sun May 30, 2021 2:08 am I've noticed that a syntax error in a handler.lua file does throw an error but not detailed enough? Like there is no line number where the syntax error is.
Thanks for the report! There was an internal error in the error reporting function. Oops. It's been fixed now.
Tools: Hot Particles, LuaPreprocess, (more) Games: Momento Temporis: Light from the Deep, Energize!
"If each mistake being made is a new one, then progress is being made."
User avatar
ReFreezed
Party member
Posts: 298
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

LuaPreprocess update 1.14

Post by ReFreezed »

Update 1.14

Changes since 1.13.2:

Library:
  • !(), !!() and @insert now work in macros.
  • Macro names can now contain lookups.
  • Updated string serialization, including for newToken("string").
  • Fixed error in output for @line.."" .
  • Improved some error messages.
LuaPreprocess also has a new website! Documentation has moved here.
Tools: Hot Particles, LuaPreprocess, (more) Games: Momento Temporis: Light from the Deep, Energize!
"If each mistake being made is a new one, then progress is being made."
User avatar
yetneverdone
Party member
Posts: 391
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Re: LuaPreprocess - straightforward preprocessor with simple syntax

Post by yetneverdone »

How does one insert a table to another like:

Code: Select all

!(
local t = {
	{1},
	{2},
	{3},
)

local t2 = {
 	--insert contents of `t` here,
 	{4},
 	{5},
}
a solution ive found is:

Code: Select all

!(
t_player = {
	{"sheet_player_idle_normal", path_images .. "player/sheet_player_idle_normal.png"},
	{"sheet_player_walk_normal", path_images .. "player/sheet_player_walk_normal.png"},
	{"sheet_player_run_normal", path_images .. "player/sheet_player_run_normal.png"},
	{"sheet_player_open_door_normal", path_images .. "player/sheet_player_open_door_normal.png"},
}
function get_t_player()
	local str = ""
	for _, t in ipairs(t_player) do
		str = str .. toLua(t) .. ",\n"
	end
	return str
end
)
--usage
local t = {
	!!(get_t_player())
}
But maybe theres another way of like copy-pasting a table into the output code?
User avatar
ReFreezed
Party member
Posts: 298
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: LuaPreprocess - straightforward preprocessor with simple syntax

Post by ReFreezed »

The first code snipped has an error, which confused me at first. (I assume there's supposed to be an additional `}` after `{3},`).

Also, the code snippets seem to show different things you're trying to do. To insert things from a table in the metaprogram into a table in the final program you can do this:

Code: Select all

local t2 = {
	!for _, v in ipairs(t) do
		!(v),
	!end
	{4},
	{5},
}

-- Output:
local t2 = {
		{1},
		{2},
		{3},
	{4},
	{5},
}
!(expression) serializes and outputs a value.

For the second code snipped you can just do this:

Code: Select all

local t = !(t_player)
Tools: Hot Particles, LuaPreprocess, (more) Games: Momento Temporis: Light from the Deep, Energize!
"If each mistake being made is a new one, then progress is being made."
User avatar
yetneverdone
Party member
Posts: 391
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Re: LuaPreprocess - straightforward preprocessor with simple syntax

Post by yetneverdone »

Im going to insert the contents of the table in many places many times so doing a for-loop is not favourable. Any other method?
User avatar
ReFreezed
Party member
Posts: 298
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: LuaPreprocess - straightforward preprocessor with simple syntax

Post by ReFreezed »

yetneverdone wrote: Thu Jul 29, 2021 9:47 am Im going to insert the contents of the table in many places many times so doing a for-loop is not favourable. Any other method?
Why is a for-loop not favorable?

Anyway, instead of having get_t_player() you could instead make the function output the code directly.

Code: Select all

!(
function output_t_player()
	for _, t in ipairs(t_player) do
		outputValue(t)
		outputLua(",\n")
	end
end
)
local t = {
	!output_t_player()
}
Or more generically...

Code: Select all

!(
function output_comma_separated_values(values)
	for _, v in ipairs(values) do
		outputValue(v)
		outputLua(",\n")
	end
end
)
local t = {
	!output_comma_separated_values(t_player)
}
Tools: Hot Particles, LuaPreprocess, (more) Games: Momento Temporis: Light from the Deep, Energize!
"If each mistake being made is a new one, then progress is being made."
User avatar
yetneverdone
Party member
Posts: 391
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Re: LuaPreprocess - straightforward preprocessor with simple syntax

Post by yetneverdone »

The goal is to make the function more abstract so it can return other tables by id as well over multiple places where it may be repeated. thanks for the help
User avatar
ReFreezed
Party member
Posts: 298
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

LuaPreprocess update 1.15

Post by ReFreezed »

Update 1.15

Changes since 1.14:

Library: Command line program: Also, check out the new syntax highlighter tool on the website!
Last edited by ReFreezed on Mon Aug 02, 2021 12:23 am, edited 1 time in total.
Tools: Hot Particles, LuaPreprocess, (more) Games: Momento Temporis: Light from the Deep, Energize!
"If each mistake being made is a new one, then progress is being made."
Post Reply

Who is online

Users browsing this forum: No registered users and 26 guests