lua-users home
lua-l archive

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


Gang,

Tons of thanks for all the various help... Definitely moving forward with
your collective insights.

Ok... I now have the basics of lua embedded.  I'm now trying to figure out
how to pass arguments to my lua code.  I'm also trying to do this as
efficiently as possible.

Here is my current situation:

I have this text in memory of a lua script:

"function main(value)
   print(value)
end"

Now, correct me if I'm wrong, but I've learned that when I lua_load that
text, it actually creates an new implied function around it:

(braces mean implied)

[function implied()]
    function main(value)
        print(value)
    end
[end]

I deduce this because lua_loading and lua_calling the text above does
absolutely nothing.   But If I change the text to:

"function main(value)
   print(value)
end

main(4)"

And lua_load it, getting the implied:

[function implied()]
    function main(value)
        print(value)
    end

    main(4)
[end]

And run this: implied runs, inside of which it calls main which then prints
out 4 (as expected);

However, what I REALLY want is to have a way to make lua_load NOT add the
implied function.  Is there a way to do this?

---

If I'm stuck with this, what is the most efficient way to then call main
from my C code, passing a value and being (hopefully) very efficient.

>From what I can tell, the only way is to have the implied function on the
stack, do a getfenv() to get its environment table on the stack, then parse
that to find out info about main -- don¹t know what I'm really looking for
there or what to do with it once I find it -- but once I do, then use it to
call main, using the standard push calls to pass arguments...

But that seems VERY VERY VERY inefficient!

If I can just get the compiled code of "main" OR if I could get the implied
function to take the parameters I want, then there would be no need for all
sorts of look ups, etc to reduce efficiency...

So, can anyone help me out here?

I know, I know... I'm asking tons of questions.  It's a side effect of
newbie-ism...

But hey, I hope I'm at least asking some good questions and not normal
newbie q's...   :)

TIA,
Ando

-----------------
SpriTec Software
www.spritec.com