lua-users home
lua-l archive

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


"J. Perkins" wrote:
> 
> I'm trying to make a small change to the Lua
> functionality and I'm having trouble figure out how to
> do it, hoping someone here has tried something
> similar.
> 
> I'd like to use Lua as a "component description
> language", that is I'd like to write files like this:
> 
>   ComponentType
>   {
>     param1="some value",
>     param2="another value"
>   }
> 
> "ComponentType" is a C function that creates a new
> instance of the component and initializes it from the
> table data, then returns the C++ component wrapped in
> Lua table (something like Luna).
> 
> I load the component by calling a
> loadComponent(filename) function, which basically does
> a lua_dofile() to run the chunk. The problem is, after
> the chunk has run, I want to retrieve the newly
> created table from Lua so I can extract the C++
> pointer to return from the loadComponent() function.
> If I do this:
> 
>   return ComponentType{ ... }
> 
> The table is pushed on the stack and everything works
> great, but it would be nicer if I didn't need the
> return. Has anyone modified Lua to implicitly pick up
> the function return value and return it from the
> chunk? Or any pointers on how I might go about doing
> that?
> 
> Thanks for the help,
> Jason
> 379

I would find implicit returns from chunks very handy for my project,
NebLUA. For example, lo() is a function that returns the current
objects, like ls or dir. It returns a variable number of string
arguments.  My console automatically prints whatever's on top of the
stack after a call to lua. To see it's output, I have to type "return
lo()" at the console. It would be nice if that "return" could be
implicit.

--James Hearn