Page 1 of 1

[Linux]Getting any background value from the computer?

Posted: Wed Apr 29, 2015 3:21 pm
by Aprilo
What function in lua allows to get specific value from the memory address? :)

Re: [Linux]Getting any background value from the computer?

Posted: Wed Apr 29, 2015 3:41 pm
by Nixola
I don't think there's a way to do that... What do you want to achieve exactly? Why do you need such a possibly generic value?

Re: [Linux]Getting any background value from the computer?

Posted: Wed Apr 29, 2015 5:16 pm
by I~=Spam
Long rant incoming. :P

<rant length="long">

Yeah you should never need that... but if you REALLY need it... you could make a c library. I think you are trying to access a value across separately run binaries/applications. If this is what you are trying to do it will never work. The x86 and x86_64 processors are built so that this isn't really possible. (The OS can do some cool stuff to make it work anyway though like windows did to allow 16bit programs to run even in windows vista.)

But keep in mind that a pointer in one application NOT pointing to the same value in another application. This is intentional in Linux. For every single memory call Linux internally redirects the processor to where the memory actually is. So the pointer 0x12345678 doesn't actually point to that location. The location that this pointer will point to it unique to the application running and will actually represent memory somewhere else (such as at 0x87654321).

In a nutshell, applications are sandboxed. This is for a good reason because now it is theoretically possible to make an OS that cannot crash. (that doesn't happen in practice though of course) Now a misbehaving application doesn't cause a blue screen of death (or a kernel panic).

Lastly, even if it is possible. It is a REALLY, REALLY, REALLY bad idea. There are solid standards for sharing memory between applications that have been around for a long time now.

</rant>

Re: [Linux]Getting any background value from the computer?

Posted: Wed Apr 29, 2015 5:25 pm
by konacake
I'm assuming he's asking for an environment variable, since getting a memory address would be the most useless thing in the world. For that you'd want to learn about os.execute and shell scripting (probably BASH).

Re: [Linux]Getting any background value from the computer?

Posted: Wed Apr 29, 2015 5:28 pm
by Nixola
You can get an environment variable using os.getenv I think

Re: [Linux]Getting any background value from the computer?

Posted: Wed Apr 29, 2015 5:57 pm
by I~=Spam
That might be it but he is asking "value from the memory address"... I am not sure how that is an environment variable...

Re: [Linux]Getting any background value from the computer?

Posted: Wed Apr 29, 2015 7:00 pm
by s-ol
I~=Spam wrote:That might be it but he is asking "value from the memory address"... I am not sure how that is an environment variable...
Environment variables are stored in a specific memory position, in C getenv (?) returns a pointer. I'd guess he thinks it's the same in Lua.

Re: [Linux]Getting any background value from the computer?

Posted: Wed Apr 29, 2015 7:32 pm
by I~=Spam
S0lll0s wrote:
I~=Spam wrote:That might be it but he is asking "value from the memory address"... I am not sure how that is an environment variable...
Environment variables are stored in a specific memory position, in C getenv (?) returns a pointer. I'd guess he thinks it's the same in Lua.
Yes the variables must be stored somewhere... and strings are arrays of characters which is accessed by a pointer. In lua strings are not pointers because the interface is abstracted away. If he wanted the string I think he would have asked for a string not a value at an address. Why would he ask for the value at an address unless he already had an address in mind? No lua function returns a raw address. So he must have been trying to do something he shouldn't.

Re: [Linux]Getting any background value from the computer?

Posted: Thu Apr 30, 2015 11:50 am
by s-ol
I~=Spam wrote:
S0lll0s wrote:
I~=Spam wrote:That might be it but he is asking "value from the memory address"... I am not sure how that is an environment variable...
Environment variables are stored in a specific memory position, in C getenv (?) returns a pointer. I'd guess he thinks it's the same in Lua.
Yes the variables must be stored somewhere... and strings are arrays of characters which is accessed by a pointer. In lua strings are not pointers because the interface is abstracted away. If he wanted the string I think he would have asked for a string not a value at an address. Why would he ask for the value at an address unless he already had an address in mind? No lua function returns a raw address. So he must have been trying to do something he shouldn't.
We both know all that, but I'm guessing he barely knows Lua, heard specifically about pointers with getenv and doesn't know how to translate that into Lua, which I bet he is also relatively new too.

Re: [Linux]Getting any background value from the computer?

Posted: Thu Apr 30, 2015 5:59 pm
by I~=Spam
S0lll0s wrote:We both know all that, but I'm guessing he barely knows Lua, heard specifically about pointers with getenv and doesn't know how to translate that into Lua, which I bet he is also relatively new too.
Maybe.... It would be nice if he posted and clarified.... :\