ExtendedApi.lua
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

ExtendedApi.lua

Started by CrazyGuy, 26 November, 2006, 18:19:17

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

CrazyGuy

a lua file which holds a set of hubsoft independent lua functions.
I called it ExtendedApi.lua

copy it into your scripts folder and start your script with:
dofile("ExtendedApi.lua")


And all functions are available
Note that there's 2 tables reserved by it, namely tTimers and tExtUserInfo so don't declare variables with that name yourself  ;)

The file's attached, here's the API

Quote
This is the Interface for ExtendedApi.lua by CrazyGuy
Current version = 1.0


Global functions:

LuaCompat()            -- Call this function to make non LUA 5.1.x functions compatible ( as much as possible )
Serialize(tTable, sTable, sTab)         -- Returns a string in Table format for storage to file
GetExtApiVer()            -- Returns this script's version number as string


Loading and Saving related functions:

LoadStringFile(fFile)            -- Loads a textfile
SaveStringFile(sString, fFile, sMode)      -- Saves a textfile. (sMode can be the LUA modes for append, overwrite, update etc)
LoadTableFile(tTable,fFile)         -- Loads a table from a file
SaveTableFile(tTable, sTable, fFile)      -- Serializes and saves a table to a file


Multi Timers related functions:           Timers are stored in a table called tTimers

AddTimer(iInterval, sTimerName)      -- Adds a timer and returns its ID or nil on error
RemoveTimer(iTimerID)         -- Removes a timer and returns 1 on success or nil on error
GetTimerByName(sTimerName)      -- Returns a timers ID or nil on error
GetTimerByID(iTimerID)         -- Returns a timers Name or nil on error
GetTimerIntByID(iTimerID)         -- Returns a timers Interval or nil on error
GetTimerValueByID(iTimerID)         -- Returns a timers current Value or nil on error
GetTimerStateByID(iTimerID)         -- Returns a timers current State (1/0) or nil on error
StartTimerByID(iTimerID)         -- Starts a timer by ID, returns 1 on success, 0 on is already started or nil on error
StopTimerByID(iTimerID)         -- Stops a timer by ID, returns 1 on success, 0 on is already stopped or nil on error
SetTimerIntByID(iTimerID, iInterval)      -- Changes a timers Interval, returns 1 on success, nil on error
SetTimerName(iTimerID, sTimerName)      -- Changes a timers Name, returns 1 on success, nil on error
ResetTimer(iTimerID)         -- Resets a timers Value back to 0, returns 1on success, nil on error


Storing additional Userinfo functions:       Userinfo is stored in a table called tExtUserInfo

AddExtUserInfo(sName,bBool,iInt,sString)   -- Stores a set of 3 variables for the specefied user
RemoveExtUserInfo(sName)         -- Removes a user from the table
GetExtUserBool(sName)         -- Returns a boolean stored for sName or nil on error
GetExtUserInt(sName)         -- Returns an integer value stored for sName or nil on error
GetExtUserText(sName)         -- Returns a string value stored for sName or nil on error
SetExtUserBool(sName, bBool)      -- Sets the boolean value for sName to bBool, returns 1 on success, 0 on already set, nil on error
SetExtUserInt(sName, iInt)         -- Sets the integer value for sName to iInt, returns 1 on success, 0 on already set, nil on error
SetExtUserText(sName, sText)      -- Sets the string value for sName to sText, returns 1 on success, nil on error


Lemmy know if something's not working correctly or any suggestions about what to add :)


Dessamator

Looks good mate, and even if its not used directly for scripts, it can be implemented or used to quickly debugg a script.
Ignorance is Bliss.

CrazyGuy

Thnx m8  ;D

When can we expect you back in the hub  ???

Dessamator

As soon as i remember my pass  ;D, i forgot it.
Ignorance is Bliss.

bastya_elvtars

Everything could have been anything else and it would have just as much meaning.

CrazyGuy

Thnx guys  :)

Quote
There are many examples of the following in this script

if variable ~= nil then

better as...

if variable then

no?
No effectual difference, just a little cleaner code

Hmm I think I did have problems with the slight difference between "if x ~= nil then"  and "if x then"
However, that was a different script, a different LUA version and a less experienced me  :P
So let's give that another try then  8)

Updated to version 1.1 on November 27th 2006
-Added table.maxn and collectgarbage to LuaCompat (Thnx Mutor)
-Cleaned up a few "~= nil" as suggested by Mutor



Dessamator

It depends on what pattern matching you use, something you have to check :
if user=="" then..
Ignorance is Bliss.

CrazyGuy

As im not using empty string checks, but pure nil checks, it should work out fine here then

SMF spam blocked by CleanTalk