NAME

Data::Lua - Parse variables out of Lua code.

SYNOPSIS

    use Data::Lua;

    my $vars = Data::Lua->parse("foo = 'bar'");
    my $vars = Data::Lua->parse_file('lua.conf');

DESCRIPTION

This module essentially evals Lua code and returns a hash reference. The returned hash reference contains all of the top-level variables, i.e. global variables assigned outside of any functions. It currently relies on Inline::Lua to do the actual code evaluation.

Any Lua code passed to this module should be trusted; there is no checking done to verify that the code is safe, and any top-level code (outside of functions) will be run when a parse method is called.

Methods

$class->parse($string)

Parses the given string as Lua code and returns a hashref containing all of the variables defined, including functions. Returns undef if the string could not be parsed.

$class->parse_file($filename)

Like parse() but parses the given file instead of a string.

TODO

  • Provide some means of finding what the specific error was that caused a parsing problem. Currently a simple undef is returned, with no indication of why.

SEE ALSO

Inline::Lua

Lua (http://www.lua.org)

LICENSE AND COPYRIGHT

Copyright (c) 2007 Michael Fowler. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

Michael Fowler <mfowler@cpan.org>