lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



Perhaps before compilation of a Lua script a "compilation options"
script could be executed to customise the syntactic analysis. I think
the lexer would work the same, but when certain tokens are recognised
this would set off compilation events (for want of a better term). 

Let's say a call is invoked, this could trigger an optional compilation
event. The function name and arguments might be passed to an event
receiver which can change certain details. Perhaps the argument types
could be evaluated, or the function name checked, etc.

E.g.

compilation_events = {

	__function_call = function(name, args)
		if not my_function_dict[name] then
			error('function name unrecognised.')
		end
		return name, args
	end
}

Perhaps const values could be inserted by having an unrecognised name
event,

E.g.

consts = {
	red=1, green=2, blue=3
}

compilation_events = {

	__name = function(name)
		return consts[name] or name
	end
}

This could be done with something like the Lua lint implementation but
then details of the compilation events could not then be fed back to the
Lua compiler to alter certain syntactic decisions or optimisations. I
suppose we have a reflexive debug library, perhaps a similar event
library could be added with hooks tied into the compilation phase.

Just a thought, I can see how this might bloat the compiler somewhat but
I don't think the events have to be that numerous or complicated and if
they are dealt with in Lua it could be quite neat.

Nick