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
 

function string.bob()

Previous Thread :: Next Thread 
RoflBread is not online. RoflBread
Joined: 18 Jun 2009
Total Posts: 3803
01 Nov 2014 08:28 PM
Icy? Is this your alt?
Report Abuse
nicemike40 is not online. nicemike40
Joined: 19 Dec 2008
Total Posts: 1814
01 Nov 2014 08:28 PM
What is this thread even

Anyways OP what you're looking for is the __index metamethod to access 'old' string functions as well:

local oldString = string
local string = {}
function string.bob()
end

setmetatable(string, {
__index = oldString
})

Now, string.bob("Hello world") and string.sub("Hello world", 3) should both work.

If you want it in a module, check out this that I made with the same concept (actually might be better because I also expanded the string library): http://www.roblox.com/A-Better-string-Library-item?id=175473953

~Upload code to codepad-dot-org with Lua syntax highlighting to preserve indentation and make it easier to read!~
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
01 Nov 2014 08:36 PM
That wasn't very Christian of you :3
Report Abuse
ThatChristianGuy is not online. ThatChristianGuy
Joined: 14 Jun 2014
Total Posts: 1283
01 Nov 2014 08:39 PM
He's giving us a bad name.


--ThatChristianGuy
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
01 Nov 2014 08:41 PM
setmetatable(module, {
__index = string
})

I don't understand how that works so I think I'll still use my method
Unless mine is very inefficient compared to that (Thank you though, I just don't like to use things I don't understand
Report Abuse
GodShowsTheWay is not online. GodShowsTheWay
Joined: 27 Oct 2014
Total Posts: 7180
01 Nov 2014 08:43 PM
"That wasn't very Christian of you :3"

That's very ironic of you.

Report Abuse
GodShowsTheWay is not online. GodShowsTheWay
Joined: 27 Oct 2014
Total Posts: 7180
01 Nov 2014 08:45 PM
I'm giving Scripting Helpers a bad name.

My actions do not determine the actions of other Christians.
Do not judge a whole community just because of one person.

Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
01 Nov 2014 08:46 PM
Apart from the fact that as an Atheist, I don't need to be christian.

Basically, it works by saying that anything not contained in your new string library should be looked up for in the old string library.
Report Abuse
GodShowsTheWay is not online. GodShowsTheWay
Joined: 27 Oct 2014
Total Posts: 7180
01 Nov 2014 08:48 PM
Apart from the fact that no one is to go unpunished.

Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
01 Nov 2014 08:48 PM
But why does it mean that
Report Abuse
nicemike40 is not online. nicemike40
Joined: 19 Dec 2008
Total Posts: 1814
01 Nov 2014 08:49 PM
Let me explain then, because it is a better way.

So there's these things called "metatables", which are themselves tables. You can assign these metatables (which again are just tables) to be 'attached' to a normal table.

You assign the metatable to a table like this:

local normalTable = {}
local metaTable = {}
setmetatable(normalTable, metaTable)

When a metatable is attached to a table via setmetatable(), it can affect the tables (normalTable)'s behavior by using certain code-words as keys.

These code-wods all start with two underscores like this: __index (a list of them and descriptions can be found on the wiki)

The __index "metamethod" (that's what the codewords and their assigned values are called) has a nifty feature where you can make the value of it ANOTHER table. Then, if someone tries to access a nil value in 'normalTable' and we have
metaTable = {__index = anotherTable}
, then they'll actually get the index in 'anotherTable' instead!

So when I'm setting the metatable of our local 'string' table to have __index=oldString, that means that when someone does this:

string.sub

, the code is like "hey, string (a local table) doesn't have sub! Let's use oldString.sub instead"

Get it now?

~Upload code to codepad-dot-org with Lua syntax highlighting to preserve indentation and make it easier to read!~
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
01 Nov 2014 08:50 PM
the __index metatable method thingy is called when a value is looked up in the table.
If a table is set to __index, then it means that when the key is not found in the original table, it checks the __index table. YOu can abuse these for OOP inheritance and tailcalls.
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
01 Nov 2014 08:51 PM
Yes I think I get it now (Get what its doing, still don't clearly understand metatables very well)

Thanks
Report Abuse
Previous Thread :: Next Thread 
Page 2 of 2Go to page: 1, [2] Prev
 
 
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