|
| 26 Jan 2013 07:22 PM |
Dear Scripting Helpers,
I am creating a ROBLOX GUI Effects Engine/API using tables. I'm trying to find an easier method for "importing" these global tables via a function. I have heard of using metatables + set/getfenv to integrate all table functions directly into the script. Here's what I'm currently doing: local api = _G.AbsoluteEngine api.ImAFunction()
I would like to do the following: _G.ImportAbsoluteEngine() -- Code that sets function environments and integrates it into the script ImAFunction()
Now, what is the code that would go in ImportAbsoluteEngine()? I know it involves set/getvenv and possibly metatables. FYI: The table that contains all API functions is called _G.AbsoluteEngine
Thank you in advance for your help.
<< AʙsᴏʟᴜᴛᴇLOL - Fᴏʀsᴀᴋᴇɴ Pʀɪᴍᴇ Gᴇɴᴇʀᴀʟ >> |
|
|
| Report Abuse |
|
|
Garnished
|
  |
| Joined: 09 Apr 2012 |
| Total Posts: 12695 |
|
| |
|
|
| 27 Jan 2013 09:21 AM |
| Thing is, you can't do it the way you are trying. The problem is that when you call a function located in _G, it executes the function from the script it is located in, not the script that you are calling it from. |
|
|
| Report Abuse |
|
|
|
| 27 Jan 2013 09:23 AM |
Okay, that is fine. But what is the snippet you would stick at the top of the script you're "importing" it into?
<< AʙsᴏʟᴜᴛᴇLOL - Fᴏʀsᴀᴋᴇɴ Pʀɪᴍᴇ Gᴇɴᴇʀᴀʟ >> |
|
|
| Report Abuse |
|
|
ilovearak
|
  |
| Joined: 15 Oct 2007 |
| Total Posts: 13 |
|
|
| 27 Jan 2013 09:25 AM |
_G.poop_table = {poop = function(a) print("pooped ".. a .."kg poop") end}
local poop_lib = _G.poop_table
function import_lib(reference) for i,v in pairs(reference) do getfenv()[i] = v end end
import_lib(poop_lib)
poop(23)
k |
|
|
| Report Abuse |
|
|
|
| 27 Jan 2013 09:25 AM |
One moment, let me test this...
<< AʙsᴏʟᴜᴛᴇLOL - Fᴏʀsᴀᴋᴇɴ Pʀɪᴍᴇ Gᴇɴᴇʀᴀʟ >> |
|
|
| Report Abuse |
|
|
|
| 27 Jan 2013 09:26 AM |
How to do it:
The engine script:
_G.AbsoluteEngine = { MyFunction = function(String) print("String") end, }
The script you are using the engine from:
for i,v in pairs(_G.AbsoluteEngine) do getfenv()[i] = v end MyFunction() |
|
|
| Report Abuse |
|
|
| |
|
|
| 27 Jan 2013 09:28 AM |
I officially love you. Thank you. *gives super sweet chocolate cookie*
<< AʙsᴏʟᴜᴛᴇLOL - Fᴏʀsᴀᴋᴇɴ Pʀɪᴍᴇ Gᴇɴᴇʀᴀʟ >> |
|
|
| Report Abuse |
|
|