generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Easier API Creation

Previous Thread :: Next Thread 
AbsoluteLOL is not online. AbsoluteLOL
Joined: 01 Dec 2012
Total Posts: 3939
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 is not online. Garnished
Joined: 09 Apr 2012
Total Posts: 12695
27 Jan 2013 09:06 AM
*getfenv


Report Abuse
kirkyturky12 is not online. kirkyturky12
Joined: 30 Apr 2010
Total Posts: 1915
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
AbsoluteLOL is not online. AbsoluteLOL
Joined: 01 Dec 2012
Total Posts: 3939
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 is not online. 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
AbsoluteLOL is not online. AbsoluteLOL
Joined: 01 Dec 2012
Total Posts: 3939
27 Jan 2013 09:25 AM
One moment, let me test this...

<< AʙsᴏʟᴜᴛᴇLOL - Fᴏʀsᴀᴋᴇɴ Pʀɪᴍᴇ Gᴇɴᴇʀᴀʟ ​>>
Report Abuse
kirkyturky12 is not online. kirkyturky12
Joined: 30 Apr 2010
Total Posts: 1915
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
kirkyturky12 is not online. kirkyturky12
Joined: 30 Apr 2010
Total Posts: 1915
27 Jan 2013 09:27 AM
Derp. Late toasted again.
Report Abuse
AbsoluteLOL is not online. AbsoluteLOL
Joined: 01 Dec 2012
Total Posts: 3939
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image