lua-users home
lua-l archive

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


On Tue, 24 Apr 2012 16:31:51 -0400
"James Urso" <JUrso@walchem.com> wrote:

> Is there something I can do so that I don't need to have the "th." In
> front of the call to the buildMessage function in the C library?
> Eventually, I plan to take the function call out of here and pass in
> an input file name as a command line parameter.  The input file will
> be the script file written by the software developers and it will
> simply contain a series of buildMessage() calls and calls to other
> soon-to-be-developed functions.
> 
>  
> 
> For simplicity, I would prefer that the developers not have to put
> "th." In front of every function call.  I've Googled for answers but
> haven't really found any.  One webpage I found had an example that
> seemed to do what I wanted, but it was written in Lua 5.1 and used
> some deprecated functions.  Any suggestions to solve this issue would
> be appreciated.
> 

Gah sorry, that sent well before I was ready.

Two things here; The first is that in Lua 5.2 the require function
doesn't set a global any more, and the second is that luaL_newlib()
populates a table with your functions. Your open function returns that
table, so you have to capture the value from require() as you noticed.

If you use the lua_register() macro you can set globals directly if
that's what you want to do:

lua_register (L, "buildMessage", create_message);

Probably you have a lot of functions so you want to do that as an
iteration over the testHarness[] array to set them all up.