Results 1 to 2 of 2

Thread: Set of functions in a table to be used by other objects ('library')

  1. #1

    Set of functions in a table to be used by other objects ('library')

    Hi folks - need help plz:

    What's the purpose?
    An "engine" should provide variables (works), tables (works), a generic set of functions (works fine), and - thats the point - a table of functions to be "copied" for a series of objects spawned.

    (I do not want to use Global)

    --object called the engine:
    g_func = {}
    function onLoad()
        Global.setVar('engineGUID', self.getGUID())
    function buildLibraries()
        g_func.initialize = function (x) print('initialized ' .. x) end
        --more to be built
        --test, works:
    --other objects want to "copy" the function table to itself
    myE = {}
    myE_func = {}
    function onLoad()
        myE = getObjectFromGUID(Global.getVar('engineGUID'))
        myE_func = myE.getTable('g_func')
    When the function table () is to be assigned, this error is thrown:
    "Attempt to perform operations with resources owned by different scripts."

    What I am trying to do is "make me copy of a function-table set" - LUA seems to be easy to store functions in a table:

    Even if I set the myE_func to local in the onLoad part, it doesnt work.

    (I did a lot of reading and trying, but couldnt find a way).

    Whats the reason for that? How to make it work? What mistake do I make?



  2. #2
    Moonsharp (Lua emulator written for C# that TTS uses for running scripts) does not allow sharing functions between "script objects", and currently every game object and Global are separate scripts. Therefore they cannot be shared directly, even if those functions have no upvalues etc.

    A workaround for some subset of function would be to serialize them with string.dump(fcn), which we can do, and then load the resulting bytecode in another object using loadstring(dumpString), which we can't do because we don't have access to loadstring. In my opinion, for no reason at all, but that's a different story.

    All in all, you pretty much have to resort to cross object calls ('someFunctionName', singleParamTable) ), which are a pain in the ass. This topic (how to make it work without going mad) is quite often discussed on the Discord, feel free to join and hit up up on the #scripting channel

Similar Threads

  1. [SUPPORT] Missing library in linux version.
    By ToyotaFanKK in forum Technical Support
    Replies: 0
    Last Post: 11-11-2018, 03:28 PM
  2. How to sink button objects in the table?
    By springboard in forum Scripting
    Replies: 2
    Last Post: 06-07-2018, 02:56 PM
  3. Game slows to a crawl when loading a library of over 500 games
    By TheRealHopScotch in forum Bug Reports
    Replies: 0
    Last Post: 12-07-2017, 09:13 PM
  4. Standard Library for Tabletop Simulator
    By Banbury in forum Scripting
    Replies: 46
    Last Post: 10-05-2017, 05:07 AM
  5. Replies: 7
    Last Post: 07-17-2017, 06:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts