Author Topic: variable/context sharing between python/lua  (Read 292 times)

0 Members and 1 Guest are viewing this topic.

leon

  • Newbie
  • *
  • Posts: 9
    • View Profile
variable/context sharing between python/lua
« on: November 15, 2018, 09:49:02 AM »
Is GeeXLab intended to work with either LUA or Python?
I just played around, and it seems i can do both at the same time :)
Is this a bug or feature? :)

If it's a feature: is it possible to

  • access a value both in python and lua?
  • OR call a python function in lua (or vice versa)

I know this kind of an odd question, I just happened to run into this scenario: I started something in python, but found an interesting utility lib written in lua.
I can find a similar lib written in python, i was just curious since GeeXLab does not require me to choose either python or lua  :-\


JeGX

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1722
    • View Profile
    • Geeks3D.com
Re: variable/context sharing between python/lua
« Reply #1 on: November 15, 2018, 11:14:27 AM »
Is GeeXLab intended to work with either LUA or Python?
I just played around, and it seems i can do both at the same time :)
Is this a bug or feature? :)

GeeXLab is designed to work with Lua, or Python or both scripting languages at the same time. It's not a bug, it's a feature. Lua and Python are just tools to create you demo/app with GeeXLab. You can use both languages in the same demo. For example, you can have two INIT scripts (one in Lua and one in Python) and one FRAME script in Lua. You are free.


If it's a feature: is it possible to

  • access a value both in python and lua?
  • OR call a python function in lua (or vice versa)

Scripting languages live in their own virtual machine/world. They are isolated from each other and can not work directly together. I found a simple workaround: shared variables. Shared variables (SV) allow you to create special variables that can be read/write by Lua and Python. You create a SV in Lua and a Python script can read it and write it.

SVs are managed by the gh_utils.shared_variable_xxxxxxx() set of functions.

There is a demo in the full code sample pack:
gl-21/lua-python-shared-variables/shared_var_01.xml

In the demo a SV (lua_counter) is created and incremented every frame in Lua. This variable is read in Python and displayed.

GeeXLab - shared variables, Lua + Python


There is no way to call a Python function in Lua (or vice-versa).

You can also develop your own shared variables system by using files to exchange data...

Hope that helps.



leon

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: variable/context sharing between python/lua
« Reply #2 on: November 15, 2018, 11:17:19 AM »
Thanks for the detailed reply.
This is amazing, shared variables are totally fine for sharing simple data etc.