Jump to content




[1.33] CycloDat v0.2

api

  • You cannot reply to this topic
7 replies to this topic

#1 Cyclonit

  • Members
  • 50 posts
  • LocationGermany

Posted 24 July 2012 - 08:32 PM

Introduction

Hi there,

over the past few days, I have been working on an API for saving variables beyond the runtime of computers and turtles. The resulting code enables storing of numbers, strings, booleans, tables and nested tables. Saved variables can be found in the file called "database" in your computer's (or turtle's) directory on your PC and thus cannot be shared between computers or turtles using this API.

If you have any bug reports, suggestions or general feedback on how I could improve this API please let me know =)

-Cyclonit


Features:
  • easy to use
  • type persistence
  • supports all primitive types
How to

Installing the API:
  • Download the API using this link: Mediafire download or by copying it from the Pastebin site.
  • Download my CycloFramwork API using this link: Mediafire download or by copying it from the Pastebin site.
  • Move both files into "modsComputerCraftluaromapis"
  • Optional: You must remove any file extensions from the downloaded files, if your PC decided to add them.
  • Optional: Load the APIs using "os.loadAPI("/rom/apis/cd")" and "os.loadAPI("/rom/apis/cd")" respectively. (Not necessary if you put the files into "modsComputerCraftluaromapis".)

Commands:
  • save(string name, string/boolean/number/table value) - Saves the given value using the given name.
  • saveRaw(string name, string value) - Saves the given value without converting it.
  • load(string name) - Returns the stored value of the named variable.
  • loadRaw(string name) - Returns the stored value of the named variable without converting it.
  • delete(string name) - Deletes a variables value from the database.
  • list() - Returns a list containing all stored variables.
  • listPrint() - Prints a list containing all stored variables to the terminal.

Source Code

CycloDat v2.0: Pastebin

CycloFramwork v2.0: Pastebin



Changelog:

v0.2:

  • split save(...) into save(...) and saveRaw(...) for higher flexibility
  • split load(...) into load(...) and loadRaw(...) for higher flexibility
  • moved conversion and text utility functions to the CycloFramework


#2 Tiin57

    Java Lunatic

  • Members
  • 1,412 posts
  • LocationIndiana, United States

Posted 24 July 2012 - 08:45 PM

Good job.

#3 KyleBoyer

  • New Members
  • 4 posts

Posted 25 July 2012 - 03:43 AM

View PostCyclonit, on 24 July 2012 - 08:32 PM, said:

Introduction

Hi there,

over the past few days, I have been working on an API for saving variables beyond the runtime of computers and turtles. The resulting code enables storing of numbers, strings, booleans, tables and nested tables. Saved variables can be found in the file called "database" in your computers (or turtles) directory on your PC and thus cannot be shared between computers or turtles using this API.

If you have any suggestions on how I could improve this API please let me know =)

-Cyclonit


Features:
  • easy to use
  • type persistence
  • supports all primitive types
How to

Installing the API:
  • Download the API using this link: Mediafire download.
  • Move the file into "modsComputerCraftluaromapis"
  • Load the API using "os.loadAPI("/rom/apis/CycloDat")"
Commands:
  • save(string name, string/boolean/number/table value) - Saves the given value using the given name.
  • load(string name) - Returns the stored value of the named variable.
  • delete(string name) - Deletes a variables value from the database.
Additional commands:
  • list() - Returns a table containing all currently saved variables as keys for their respective values.
Source Code







Spoiler

I would love to use this but I cannot figure out how to. :/

#4 Sxw

  • Members
  • 306 posts
  • LocationWhenever, Wherever!

Posted 25 July 2012 - 04:10 AM

Awesome, ima use this in my first (useful) program.

#5 Cyclonit

  • Members
  • 50 posts
  • LocationGermany

Posted 25 July 2012 - 07:11 AM

@KyleBoyler: Did you follow the steps in the installation section? As soon as you did that you can use the commands by writing "CycloDat." and the command right after.

#6 Calculator

  • Members
  • 14 posts
  • LocationBelgium

Posted 27 July 2012 - 12:57 PM

Nice work, but did you know that ComputerCraft already comes with functions to encode tables to strings and decode them afterwards?
You should check out textutils.serialize(table) and textutils.unserialize(string). :)/>

#7 Cyclonit

  • Members
  • 50 posts
  • LocationGermany

Posted 27 July 2012 - 02:10 PM

@Calculator: I knew that but it seems as if my function is more stable than the build in ones. Both ways were tested by myself and the serialize+unserialize method breaks at about 24000 table elements. Since my method additionally in most cases is as fast as the build in one and pretty much as often faster as it is slower, I do not see any reason to use serialize and unserialize ^^.


P.S.: I used randomly generated tables for testing. They contained strings, numbers, booleans and additional tables.

#8 Cyclonit

  • Members
  • 50 posts
  • LocationGermany

Posted 03 August 2012 - 07:19 PM

Version 0.2 is now online. I optimized some of the functions and reorganized them for better compatibility with upcoming APIs. I did not test this API under 1.4 yet. Feedback is appreciated =)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users