Hi Patrick,

You’re right. This question was already ask.

I can’t move the converters in the global context because
some converters linked with a session. for example:

 - capture-req
 - capture-res
 - set-var
 - unset-var

Maybe we can add a flag to each converter to known if they use a session
or no, and import the sessionless converter in a global object ?

Sometime ago, I wrote this message. I do not yet test the proposed
solution, but you can try:

=============================================================

Hi, Maybe I'm wrong, but it seems that the server is choosed after the
Lua executions (action or sample fetch), so it is not possible to known
the chossen serveur during Lua phase.

In other way, the choice of the server is not easy and it is not easiy
predictible.

The converters are static functions, and they can run during the init
phase, but there are not accessible. Maybe it have an ugly solution
that consist to create a fake object Converter and use it. The
following code is just a guideline, it is not tested, and the Lua
syntax is not checked.

  -- Get the metable of converters searching in in the Global object
  -- I assume the variable meta_converter contains this metatable
  meta_converter = ...

  -- Create new object which is an array containing specific content
  -- in the slot "0"
  convs[0] = 0
  set_metatable(convs, meta_converter)

  -- Now conv is a Converter object, and maybe it can execute some
  -- converters.
  convs:crc32("test")

I'm afraid that this method doesn't work or in the worst case produce
segfault, but you can try.

In other way, if you are able to procude some line of C, you can export
the hash function from haproxy in a file. These function are autonomous
and doesn't have dependencies. You create your own Lua library
containing these two functions. You will find easyly tutorials.

BR,
Thierry

=============================================================


BR,
Thierry


> On 30 Apr 2018, at 22:19, Patrick Hemmer <[email protected]> wrote:
> 
> Right now in LUA, all the HAProxy converters are accessible through the 
> `Converters` class. However this class is only accessible through the TXN 
> class. Can we get this changed so that the Converters class is a global?
> 
> My intent is to be able to call a builtin HAProxy converter from within a 
> custom LUA converter. However the LUA converter prototype does not receive a 
> TXN, so I have no access to the the Converters class. Converters are supposed 
> to be stateless, so I see no reason why they should be accessible only from 
> within the TXN class.
> 
> -Patrick


Reply via email to