[Resolved - Alternative Exist] Make import of other script in one-line

Hello Cfx Team and the Community,

As it has already been mentioned many times it is impossible to share the metatables of a Lua object between scripts, and this includes the choices to go through exports and events (to name only the main ones), in any case I do not not here to start a discussion on this specific isolation which is basically not a bad thing

In a topic involving PichoM & d-bubble in a really intersting discussion, d-bubble mentioned that metatable references have already been planned (is this still the case ?).

After reflection, I was wwondering if it’s was possible to allow through the fxmanifest a way to list all the files wich could reprensets library files to be imported from a script and to allow in some way to add in the files to load, to a script all the files that would have been imported.

This could take the form of an fximport.lua file at the root of the script and which would only contain a table with 3 indexed table witch represents each one a scope with the list of files return through the import function described after :

{
    share = { "file1.lua", "file2.lua" },
    server = { "file4.lua" },
    client= { "file3.lua" }
}

and the specified function available in the fxmanifest.lua with a result handled through the script loading line:

shared_scripts(import("MyScript"))

And the code behind the shared_scripts function would directly take the right “sub table”

Thanks for your time,
Doggy

… I’m not sure what you’re even suggesting here as the description of the requested feature is unclear and you’re not explaining some assumptions you’re making.

You can already add stuff from other resources using @ syntax in the file name or using load(LoadResourceFile(...)), and nothing is stopping a resource from doing this using a single file that then imports further scripts from itself.

1 Like

Hello,

I actually read again my first post and it was really unclear.

I thought that the file load methods was disabled in the lua scripts runtime environnement. But I did some tests, and it seems to work perfectly ! Given that, this request for functionality no longer necessarily makes sense.

Thank you for your remark d-bubble and have a nice day !

For people wanting to make a file wich will make quick import of a specified script, i’ve make a gist on github sharing the one i’ve done