Getting locals in C++

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting locals in C++

Martin, Marcus

 

If I have the following Lua code

 

--Some method

function Main(instance)

 

    local fid = 17

    InvokeCMethod()

End

 

Can I get at the value of the above local variable from within the InvokeCMethod (in C code)? How would I do that?

 

Marcus

 

Reply | Threaded
Open this post in threaded view
|

Re: Getting locals in C++

Patrick Donnelly
Hi Marcus,

On Thu, Jun 4, 2009 at 4:26 PM, Martin, Marcus<[hidden email]> wrote:
> Can I get at the value of the above local variable from within the
> InvokeCMethod (in C code)? How would I do that?

See these functions:

http://www.lua.org/manual/5.1/manual.html#lua_getstack
http://www.lua.org/manual/5.1/manual.html#lua_getlocal

--
-Patrick Donnelly

"Let all men know thee, but no man know thee thoroughly: Men freely
ford that see the shallows."

- Benjamin Franklin
Reply | Threaded
Open this post in threaded view
|

Re: Getting locals in C++

Javier Guerra Giraldez
In reply to this post by Martin, Marcus
Martin, Marcus wrote:
> function Main(instance)
>     local fid = 17
>     InvokeCMethod()
> End
>
> Can I get at the value of the above local variable from within the InvokeCMethod (in C code)? How would I do that?

besides checking the Lua internals, note that if that were a Lua function, it wouldn't be able to access locals either.  Doing something different in C is straining the contract between caller and callee, at the very least.


--
Javier
Reply | Threaded
Open this post in threaded view
|

RE: Getting locals in C++

Martin, Marcus
Yeah, I have realized this is not a good idea and solving my issue another way.

-----Original Message-----
From: Javier Guerra [mailto:[hidden email]]
Sent: Thursday, June 04, 2009 10:33 PM
To: [hidden email]
Cc: Martin, Marcus
Subject: Re: Getting locals in C++

Martin, Marcus wrote:
> function Main(instance)
>     local fid = 17
>     InvokeCMethod()
> End
>
> Can I get at the value of the above local variable from within the InvokeCMethod (in C code)? How would I do that?

besides checking the Lua internals, note that if that were a Lua function, it wouldn't be able to access locals either.  Doing something different in C is straining the contract between caller and callee, at the very least.


--
Javier