Combining LUA with C cross different tasks
  • Moderator
    Kronos
    Posts: 2237 from 2003/2/24
    O.k. so I downloaded the lua-archive from morphos-files to get the needed includes (or are there newer ones to be found elswhere ?) and I got as far as having 1 C program calling a LUA script which than calls a function in that C program. NICE.

    Now, what I would like to do is to call that function from elsewhere. So another program starting that script (like LuaX) or even another program calling it directly with lua.library.

    Is that even possible, or would I need to define that function as an ARexx command in my C code ?
  • »25.10.14 - 16:28
    Profile
  • MorphOS Developer
    Krashan
    Posts: 1107 from 2003/6/11
    From: Białystok...
    O.k. so I downloaded the lua-archive from morphos-files to get the needed includes (or are there newer ones to be found elswhere?)

    Newer ones are in the current public MorphOS SDK...

    Now, what I would like to do is to call that function from elsewhere. So another program starting that script (like LuaX) or even another program calling it directly with lua.library.

    I don't really get the problem. If you have a Lua script in a file, any number of Lua interpreter instances can load and execute this file.
  • »25.10.14 - 21:49
    Profile Visit Website
  • Moderator
    Kronos
    Posts: 2237 from 2003/2/24
    The public SDK ? Who would use that ...... ;)

    Quote:

    I don't really get the problem. If you have a Lua script in a file, any number of Lua interpreter instances can load and execute this file.


    O.k. lets make it more clear:

    Compiled C program No1 defines function foo() and registers it with LUA
    Compiled C program No2 executes Lua script No3.
    Lua script tries to call foo() (while No1 is still running offcourse)
  • »25.10.14 - 21:59
    Profile
  • MorphOS Developer
    Krashan
    Posts: 1107 from 2003/6/11
    From: Białystok...
    This is not possible. When you register a C function in Lua, its visibility is limited to a single interpreter instance obtained with LuaNew(). Different instances are independent and not "know" of each other. One could try to share interpreter instance between processes, but it will crash and burn. The most elegant way is in fact exposing this function as an ARexx command. Alternatively, it foo() may be isolated from defining application, you can place it in a module, which can be later require()-d by any script.

    [ Edited by Krashan 26.10.2014 - 09:30 ]
  • »26.10.14 - 08:27
    Profile Visit Website
  • Moderator
    Kronos
    Posts: 2237 from 2003/2/24
    Well I guess it's ARexx than ;)
  • »26.10.14 - 10:31
    Profile