Software Lua - libraries

StefanE

Donator
Donator
Joined
Feb 27, 2008
Messages
21
Reaction score
0
Points
0
Location
Freiburg Germany
Hi everybody,

I am trying to get data out of Orbiter (2010 P1) to a 2nd Computer via RS232 or TCPIP, using the lua-interface.


There are libraries for serial communication available (e.g. luars232), but the Orbiter-Lua-Interface does not seem to recognize them. As soon as I put a line "rs232 = require ('luars232') in my script, I get the usual Execution Error. Somehow I have to tell Orbiter where to look for lua-libraries, but where? I did not find any hint. Maybe the Orbiter-Lua-Interface does not accept external libraries? I did not find a single example of a lua-File within the Orbiter 2010 P1 Installation which uses the 'require'-statement. It should be mentioned, that a full lua-Installation is running on the same computer without the a.m. restriction.

Kind regards
StefanE

P.S.

Please do not consider any alternatives or workarounds like "use orbconnect" etc.
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,653
Reaction score
2,375
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
AFAIR, you just need to extend the module search path for Lua to make it find the proper modules.

I would need to look into my Lua book at home to tell you something more accurate though.
 

StefanE

Donator
Donator
Joined
Feb 27, 2008
Messages
21
Reaction score
0
Points
0
Location
Freiburg Germany
Hi Urwumpe

Not being lazy I googled for global variables in context with orbiter, and found the following:
"To determine its path, require first checks the global variable LUA_PATH". Problem is, that with a clean install of orbiter, there is no sign of a global variable in the Control Panel in connection with Orbiter (assuming Global variable means "Umgebungsvariable" in a german XP edition). Global Variables for Lua appear only with a full Lua Installation
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,653
Reaction score
2,375
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Hi Urwumpe

Not being lazy I googled for global variables in context with orbiter, and found the following:
"To determine its path, require first checks the global variable LUA_PATH". Problem is, that with a clean install of orbiter, there is no sign of a global variable in the Control Panel in connection with Orbiter (assuming Global variable means "Umgebungsvariable" in a german XP edition). Global Variables for Lua appear only with a full Lua Installation

You mistake something there: Lua also has global variables in its own script context. Which you can manipulate to your advantage or horror.

So: By the book:

require looks into the global variable "package.path", which is initialized to the environment variable "LUA_PATH". If no suitable named .lua file is found there, it looks for a C-Module under the global variable "package.cpath", which is initialized to the environment variable "LUA_CPATH".

So, in your case, if you want to load a C-module in Lua, you should either set "LUA_CPATH" and try that, or append package.cpath to contain a path to your C-module.
 
Last edited:

StefanE

Donator
Donator
Joined
Feb 27, 2008
Messages
21
Reaction score
0
Points
0
Location
Freiburg Germany
Hi Urwumpe

After several hours of unsuccessful testing i came upon the possibility to let me show the value of environment variables.

local text
text = os.getenv('LUA_PATH')
term.out(text)

This gives me: ;;C:\Programme\Lua\5.1\lua\?.luac

The same with LUA_CDIR: nil
The same with LUA_LDIR: nil
The same with LUA_INIT: nil
The same with LUA_CPATH_DEFAULT: nil

So it seems the variables we need aren't initialized?

Kind regards
StefanE
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,653
Reaction score
2,375
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
No surprise, since it should be "LUA_CPATH" without any default.
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,653
Reaction score
2,375
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
The same with LUA_CPATH: nil;)

Then try it with the package.cpath variable, if that can be set. Remember that Lua is embedded in Orbiter, but still, the environment variables should have a small effect.
 

StefanE

Donator
Donator
Joined
Feb 27, 2008
Messages
21
Reaction score
0
Points
0
Location
Freiburg Germany
Hi Urwumpe

I think the solution to this problem is an entirely different one.

When I did the first Orbiter2010-Install I allowed it to install in the default directory, which is "\Eigene Dateien" , resulting in very long path names. I removed Orbiter2010 and did a new install with the Custom-Option and chose C:\Orbiter2010. From then on it worked, including all paths which previously read "nil" now populated with meaningfull directories.

Nevertheless thank you very much.

Kind regards
StefanE
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,653
Reaction score
2,375
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
From then on it worked, including all paths which previously read "nil" now populated with meaningfull directories.

Oh, thats a pretty strange behavior.
 
Top