Page 5 of 8

Re: LuaPreprocess - straightforward preprocessor with simple syntax

Posted: Sun May 30, 2021 2:08 am
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.

Re: LuaPreprocess - straightforward preprocessor with simple syntax

Posted: Sun May 30, 2021 12:38 pm
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.

LuaPreprocess update 1.14

Posted: Mon Jul 12, 2021 11:36 pm
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.

Re: LuaPreprocess - straightforward preprocessor with simple syntax

Posted: Thu Jul 29, 2021 5:52 am
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?

Re: LuaPreprocess - straightforward preprocessor with simple syntax

Posted: Thu Jul 29, 2021 9:19 am
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)

Re: LuaPreprocess - straightforward preprocessor with simple syntax

Posted: Thu Jul 29, 2021 9:47 am
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?

Re: LuaPreprocess - straightforward preprocessor with simple syntax

Posted: Thu Jul 29, 2021 10:29 am
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)
}

Re: LuaPreprocess - straightforward preprocessor with simple syntax

Posted: Thu Jul 29, 2021 11:06 am
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

LuaPreprocess update 1.15

Posted: Sun Aug 01, 2021 4:13 pm
by ReFreezed
Update 1.15

Changes since 1.14:

Library: Command line program: Also, check out the new syntax highlighter tool on the website!

Re: LuaPreprocess - straightforward preprocessor with simple syntax

Posted: Sun Aug 01, 2021 6:47 pm
by pgimeno
I think the URLs aren't correct :nyu: