Menu

LUA Integration

Help
2012-07-04
2013-05-04
  • Nobody/Anonymous

    Is it possible to return non-string LUA variables.  A table for example?

    I'd like to use a table as a dictionary/hash for response codes.  Each time my client receives a response, I'd like to add the response code into the hash.  At the end of the program, I'd like to print out the contents of the hash.

    If I could return the initial table and pass it into each BLOCK:LUA, I'd be able to keep track easily.  Or, if LUA could save the table as a global across multiple blocks.

    For example (does not work, map seems to be interpreted as a string, not a table)

    BLOCK:LUA create_map : ret
      map = {}
      return map
    END

    BLOCK:LUA print_map map
      for k,v in pairs(map) do print("LUA2",k,v) end
    END

    BLOCK:LUA map_code map responseCode
      map = map + 1
    END

    CLIENT
      create_map map
      …send…
      _MATCH headers "HTTP/1. (+)" responseCode
      _WAIT
      map_code VAR(map) $responseCode
      …more logic
      print_map VAR(map)
    END

    The error I get is:
    client.htb:31: error: Lua error: client:49: bad argument #1 to 'pairs' (table expected, got string)

     
  • Nobody/Anonymous

    No that is not supported, httest it self supports only strings. But I will think about such a feature.

    But maybe you could solve it with httest scrippting:

    CLIENT

    _OP $my$responseCode ADD 1 my$responseCode

    _DEBUG $my302
    _DEBUG $my500

    END

    regards

     
  • christian liesch

    Try global command

    PERF:STAT on

    this will print a neat statistic at the end, it also counts the status codes….
    Works only for newer httest.

     
  • christian liesch

    Hmm sorry

    PERF:STAT ON

    capital letters, I will fix this within the next release. It should not matter if capital or not.

     
  • Nobody/Anonymous

    PERF:STAT ON works great!  Thanks for the tip.

    What is the best way to know about and learn these commands?  Is there a nice grep in the code to list the commands?   PERF:STAT (and DISTRIBUTE, RAMPUP) is not in the users-guide.  So, I've been looking in the test directory (and perf_module.c) for examples & usage.  While looking at tests, I also noticed there are _TCP commands, which I'd also like to try using.

     
  • christian liesch

    You can list commands with

    httest -L

    if you like to have more information about a command do this

    httest -C <command>

    for example httest -C _WAIT

    I know the useres guide is not up to date any more, have to work on it. Most of it is done by Marcel he has a much better english than me :)

     
  • Nobody/Anonymous

    This work well.  I am now finding many new features I look forward to trying.

     

Log in to post a comment.