lua-users home
lua-l archive

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


Dear lua developers and users

I recently decided to embed Lua into a C Application. The requirements are:
- minimal dependencies
- Linux and later windows (mingw) and OSX

For my application to work I need to set environment variables. Therefore I have written a simple Lua C extensions to do so: https://pastebin.com/NsNMHkUu

The Extension is used in Lua as follows: https://pastebin.com/YquT0Rrf

Now if I run the program, the following is happening:
 1. in the os_setenv() C function, I can successfully read back the previously set env
 2. when I try to read it back in Lua, i get garbage data as if I would have messed up with a pointer
 3. when I try to use my C function os_getenv() from the extension, I get NULL as a result.

Here is the output of the program:
-- bash output
wunderlins@wus-desktop5:~/Projects/protohand-lua/src$ make test
./protohand2.lua "mach://gedit?f=~/.profile&param1=value+1&param%202=value2&user=wus" "example.ini"
PH_HOME: /home/wunderlins/Projects/protohand-lua/src/
env (0): PH_HOME=/home/wunderlins/Projects/protohand-lua/src/, /home/wunderlins/Projects/protohand-lua/src/
� A
name: PH_HOME
env: (null)
nil unable to get environment variable 'PH_HOME'
-- end bash output

The first 2 lines of output come fro mthe C extension. 1st line from os_setenv, 2nd line from os_getenv (in my extension) and the rest is from the Lua script.

What is the mistake I am making? Any help is greatly appreciated.

My environment:
- Debian 8, x64
- gcc 4.9
- Lua 5.3.5 (compiled from source with default options and custom --prefix=)

Kind regards
-S