Jump to content




Extended String Library

api lua utility

  • This topic is locked This topic is locked
31 replies to this topic

#1 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 04 January 2013 - 12:15 PM

Thread Closed in favour of merging to a single, easier to manage, thread and website
Spoiler

Edited by TheOriginalBIT, 23 January 2013 - 07:27 PM.


#2 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 04 January 2013 - 10:12 PM

Update 1.1

Adds Java standard hashCode function!
Fixes bug in isEmpty, now evaluates as per Java implementation

#3 kornichen

  • Members
  • 220 posts
  • LocationGermany

Posted 04 January 2013 - 11:34 PM

This is so great!

#4 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 05 January 2013 - 12:21 AM

View Postkornichen, on 04 January 2013 - 11:34 PM, said:

This is so great!

Why thank you. :D

Currently out to dinner, when I get back home I'll fix up OP to explain functions and give some nicer details. So check back in a few hrs ;)

#5 GravityScore

  • Members
  • 796 posts
  • LocationLand of Meh

Posted 05 January 2013 - 09:18 AM

Wow this is useful :D. Good luck with the Objective-C library - it's like 180 functions long!

Please, in the Objective-C library add the "working with paths" functions (like [string stringByAppendingPathComponent:@"hello"], etc...).

#6 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 05 January 2013 - 11:40 AM

View PostGravityScore, on 05 January 2013 - 09:18 AM, said:

Wow this is useful :D

Thanx, I was hoping it would be useful to others. :)

View PostGravityScore, on 05 January 2013 - 09:18 AM, said:

Good luck with the Objective-C library - it's like 180 functions long!

Please, in the Objective-C library add the "working with paths" functions (like [string stringByAppendingPathComponent:@"hello"], etc...).
Yeh Obj-C isn't tiny, but it has some nice stuff. I started programming with Obj-C, and I've always liked what it had.

I shall give it a go... After I figure out exactly what it does ;) that's the hardest part sometimes. Replicating exactly what the functions do. On that note I just noticed a wrong implementation on one of the functions. Damn.

#7 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 07 January 2013 - 05:20 PM

UPDATE!

Changes:
All Versions: BUGFIXES!
v1.2: Implemented some C# functions
v1.3: Implemented some Obj-C functions

Again, if you find any bugs or have any suggestions for functions in this library, report them here

#8 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 09 January 2013 - 04:50 PM

Minor Update

Added 2 new functions:

function splitLineToTable( str, width )
Returns a table containing lines of text that do not exceed the length of the supplied width or a word being broken across two lines.

function splitLine( str, width )
Returns a string containing line breaks at the given width without splitting a word over the line

#9 anonimo182

  • Members
  • 252 posts
  • LocationIn the universe

Posted 09 January 2013 - 04:59 PM

Nice library of new functions!

#10 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 09 January 2013 - 05:04 PM

Thank you :)

If there are any that you wish to see, just post them on the suggestions page. :)

#11 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 10 January 2013 - 10:07 PM

Minor Update
v1.3.2

Added 2 new functions:


count( str, regex )
Returns the number of times the regex appears in the str


countIgnoreCase( str, regex )
Returns the number of times the regex appears in the str ignoring the case

#12 NeverCast

  • Members
  • 400 posts
  • LocationChristchurch, New Zealand

Posted 11 January 2013 - 12:43 PM

Loading this API in cc-emu crashes the computer. not tried it in actual minecraft yet. Know anything about this? Because I don't, I can't even protected call the os.loadAPI without issues.. I'll try running the code globally.. one moment

Right so after testing it seems I cannot override the global string instance with this api, correct?

#13 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 11 January 2013 - 01:16 PM

View PostNeverCast, on 11 January 2013 - 12:43 PM, said:

Loading this API in cc-emu crashes the computer. not tried it in actual minecraft yet. Know anything about this? Because I don't, I can't even protected call the os.loadAPI without issues.. I'll try running the code globally.. one moment

Right so after testing it seems I cannot override the global string instance with this api, correct?
I was gunna say "What?! I'm running cc-emu and its perfectly fine!"

Yes that is correct the string metatable is protected and cannot be modified. Doing this will work though

if not strLib then os.loadAPI( "path/to/lib/strLib" ) end

s = "Test:string"
s = strLib.replace( s, ":", " " )


#14 NeverCast

  • Members
  • 400 posts
  • LocationChristchurch, New Zealand

Posted 11 January 2013 - 02:45 PM

That explains it then! At least I can use it fine :) Thanks

#15 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 11 January 2013 - 03:26 PM

View PostNeverCast, on 11 January 2013 - 02:45 PM, said:

That explains it then! At least I can use it fine :) Thanks

Your welcome... I'm constantly adding new functions to this, if there are any you want added just report them on the suggestions page (see OP) ... One of my little side projects is to make this OO so they are dealt with like objects. so instead of doing
var = strLib.replace( var, "\r\n", "\n" ) 
you would be able to do
var = var:replace( "\r\n", "\n" )


#16 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 12 January 2013 - 02:36 AM

Update!
v2.0
  • Now has an Object version! ( See OP )
  • General bug-fixes


#17 NeverCast

  • Members
  • 400 posts
  • LocationChristchurch, New Zealand

Posted 14 January 2013 - 04:00 PM

After messing around I think you can make your string the only implementation.

lets assume that your lib is called stringx internally.
-- remember the native string table
local nativestring = string
-- create an index to it so we carry on the functions using a metatable
local stringx_mt = { __index = nativestring }
-- set the metatable to stringx
setmetatable(stringx, stringx_mt)
-- use rawset to set the string instance without invoke any metatable functions
rawset(_G, "string", stringx)

-- now later on outside the api, we can test that we successfully overrode the string table
v = "hello   "
print(v:trim())

Good luck :)

#18 NeverCast

  • Members
  • 400 posts
  • LocationChristchurch, New Zealand

Posted 14 January 2013 - 04:03 PM

It seems I may have been wrong, although you can override functions that string already has, you can't seem to create new ones. Probably because of the metatable that string has internally. I got my hopes up when I managed to make string.len return the length and print out hello world.

#19 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 14 January 2013 - 04:13 PM

yeh the string metatable is protected... believe me if it wasn't i would have been overriding it! ;)

#20 NeverCast

  • Members
  • 400 posts
  • LocationChristchurch, New Zealand

Posted 14 January 2013 - 04:16 PM

There must be a way to remove this ( Besides replace bios.lua )! *Hacker Face!*





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users