{"id":17040856,"url":"https://github.com/m4gnv5/ptrsstuff","last_synced_at":"2025-07-27T03:10:17.609Z","repository":{"id":80537434,"uuid":"57600242","full_name":"M4GNV5/PtrsStuff","owner":"M4GNV5","description":"Various scripts and libraries written in PointerScript","archived":false,"fork":false,"pushed_at":"2019-01-21T10:12:32.000Z","size":163,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-23T00:46:02.922Z","etag":null,"topics":["library","native","script"],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/M4GNV5.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-05-01T13:50:07.000Z","updated_at":"2022-04-20T01:29:41.000Z","dependencies_parsed_at":"2023-03-12T11:23:16.283Z","dependency_job_id":null,"html_url":"https://github.com/M4GNV5/PtrsStuff","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/M4GNV5/PtrsStuff","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/M4GNV5%2FPtrsStuff","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/M4GNV5%2FPtrsStuff/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/M4GNV5%2FPtrsStuff/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/M4GNV5%2FPtrsStuff/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/M4GNV5","download_url":"https://codeload.github.com/M4GNV5/PtrsStuff/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/M4GNV5%2FPtrsStuff/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267293817,"owners_count":24065326,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["library","native","script"],"created_at":"2024-10-14T09:10:44.192Z","updated_at":"2025-07-27T03:10:17.591Z","avatar_url":"https://github.com/M4GNV5.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# PtrsStuff\n\nVarious scripts and libraries written in [PointerScript](https://github.com/M4GNV5/PointerScript)\n\n## Scripts\n- `ncchat.ptrs`: Chat server you can connect to using netcat\n- `rconcat.ptrs`: [Rcon](https://developer.valvesoftware.com/wiki/Source_RCON_Protocol) client\n- `test.ptrs`: small test script for map, list, json, http and mutex libraries\n- `ircbot.ptrs`: A very basic IRC Bot that can advertise himself\n- `munchkin.ptrs`: IRC bot to play Munchkin Loot Letters\n\n## Libraries\n- `map.ptrs`:\n```C\nstruct Map\n{\n\tget count; //getter returning the count of key/value pairs in the map\n\n\tremove(key); //removes a key from the map\n\n\toperator this.key; //get a value\n\toperator this[key]; //get a value\n\toperator this.key = val; //set a value\n\toperator this[key] = val; //set a value\n\toperator \u0026this.key; //get the pointer of a value\n\toperator \u0026this[key]; //get the pointer of a value\n\toperator this.key(args...); //call a value\n\toperator this[key](args...); //call a value\n\n\toperator key in this; //check if a key exists\n\toperator sizeof this; //same as 'get count'\n\toperator foreach in this; //iterate over the map (yields key, value, \u0026value)\n}\n```\n\n- `list.ptrs`\n```C\nstruct List\n{\n\tget length; //current length of the list\n\n\toperator this[index]; //get the value at 'index'\n\toperator this[index] = value; //set the value at 'index' to 'value'\n\toperator \u0026this[index]; //get the pointer to the value at 'index'\n\toperator this[index](args...); //get the value at 'index' and call it with 'args'\n\n\toperator index in this; //same as 'index \u003e= 0 \u0026\u0026 index \u003c length'\n\toperator sizeof this; //same as 'get length'\n\toperator foreach in this; //iterate over the list (yields index, value, \u0026value)\n\n\tadd(values...); //add values to the list\n\tremoveAt(index); //removes value at 'index' and returns it\n\tremove(value, compare = (a, b) -\u003e a === b); //removes the first occurence of 'value' from the list\n\tsplice(index, removeCount, insert...); //remove and/or add multiple values\n\treverse(); //reverses the list\n\n\tindexOf(value, start = 0, compare = (a, b) -\u003e a === b); //get the first index of a value using a compare function\n\tlastIndexOf(value, start = 0, compare = (a, b) -\u003e a === b); //get the last index of a value using a compare function\n\n\t//sorts 'toArray(buff, max)' using qsort. returns the array\n\tsort(buff, max, compare = (a, b) -\u003e a - b);\n\n\t//create a new List from an array\n\tstatic fromArray(buff, length = sizeof buff);\n\t//write the entries of a list to the array. If 'buff' is NULL or undefined it returns a malloc'ed array\n\ttoArray(buff, max);\n}\n```\n\n- `array.ptrs` provides two array classes for C interop\n```C\nstruct StructArray\n{\n\tget memory; //returns the start pointer of the array\n\n\t//create a new array of type `typ[]`. `mem` can either be a pointer to memory\n\t//or an integer. If its an integer a new array `typ[mem]` is created.\n\t//if `useHeap` is true structs returned by `operator this[index]` are created\n\t//on the heap using `cast\u003ctyp\u003e` otherwise on the stack using `cast_stack\u003ctyp\u003e`\n\t//if deleteMem is true, `mem` will be deleted in the constructor\n\tconstructor(mem, typ, useHeap = false, deleteMem = typeof mem == type\u003cint\u003e);\n\n\toperator this[index]; //get the struct at `index`\n\toperator \u0026this[index]; //get the address to the struct at `index`\n\toperator index in this; //boundary check\n\toperator sizeof this; //get the size of the array\n\toperator foreach in this; //iterate over all structs in the array\n};\n\nstruct TypedArray\n{\n\tget memory; //returns the start pointer of the array\n\n\t//create a new array of type `typ[]`. Typ should be the name of the native type\n\t//e.g. \"long\", \"single\" or \"native\". `mem` can either be a pointer to memory\n\t//or an integer. If its an integer a new array `typ[mem]` is created.\n\tconstructor(mem, typ);\n\n\toperator this[index]; //get the value at `index`\n\toperator this[index] = val; //set the value at `index` to `val`\n\toperator \u0026this[index]; //get the address to the value at `index`\n\toperator index in this; //boundary check\n\toperator sizeof this; //get the size of the array\n\toperator foreach in this; //iterate over all values in the array\n};\n```\n\n- `arraylist.ptrs`\n```C\nstruct ArrayList\n{\n\tget length; //retrieve current length\n\n\tconstructor(arraylen = 127); //arraylen specifies the length of single arrays - 1\n\n\toperator this[index]; //get the value at 'index'\n\toperator this[index] = value; //set the value at 'index' to 'value'\n\toperator \u0026this[index]; //get the pointer to the value at 'index'\n\toperator this[index](args...); //get the value at 'index' and call it with 'args'\n\n\toperator index in this; //same as 'index \u003e= 0 \u0026\u0026 index \u003c length'\n\toperator sizeof this; //same as 'get length'\n\toperator foreach in this; //iterate over the list (yields index, value)\n\n\tadd(values...); //add values to the list\n\tsplice(index, removeCount); //remove 'removeCount' values at 'index'\n}\n```\n\n- `curl.ptrs`:\n```C\nstruct HTTP\n{\n\tcode; //http response code\n\theader; //response header Map (from libs/map.ptrs)\n\tbody; //response body string\n\n\t//shorthand functions for performing requests\n\t//return a new 'HTTP' instance\n\t//'reqHeader' is an optional foreach-able map of request headers\n\tstatic GET(url, reqHeader);\n\tstatic POST(url, data, reqHeader);\n};\n```\n\n- `json.ptrs`:\n```C\n//much like php's json_encode or javascript's JSON.stringify\n//returns a malloc'ed string that should be passed to free\njson_encode(val);\n\n//much like php's json_decode or javascript's JSON.parse\n//parses the json into a Map (see map.ptrs)\njson_decode(str);\n\n//destroys nested Maps/Lists generated by json_decode\njson_destroy(value);\n```\n\n- `regexp.ptrs`:\n```C\nstruct RegExp\n{\n\tconstructor(str, ignoreCase, multiLine); //compile regexp string str\n\tdestructor(); //free the regex\n\n\t//test if the regexp matches the specified string\n\ttest(str);\n\n\t//much like javascript's String.prototype.match\n\t//returns an allocated array (or NULL for no matches) that should be freed\n\tmatch(str, maxMatches = 16);\n}\n```\n\n- `timeout.ptrs`: Note, this library does not create another thread, instead it\ninterrupts the current thread and resumes to it when `func` returns.\n```js\n//executes 'func(arg)' after 'timeout' milliseconds\n//returns a 'job' that can be used with 'clearTimeout'\nfunction setTimeout(func, timeout, arg) { ... }\n\n//deletes the timeout 'job' (a value returned by 'setTimeout')\nfunction clearTimeout(job) { ... }\n\n//executes 'func(arg)' every 'interval' milliseconds\n//returns a 'job' that can be used with clearInterval\nfunction setInterval(func, interval, arg) { ... }\n\n//deletes the interval 'job' (a value returned by 'setInterval')\nfunction clearInterval(job) { ... }\n```\n\n- `socket.ptrs`:\n```C\n//AF constants (see `man socket` for more information)\n//AF_UNSPEC, AF_UNIX, AF_LOCAL, AF_INET, AF_INET6, AF_IPX, AF_NETLINK, AF_X25,\n//\tAF_AX25, AF_ATMPVC, AF_APPLETALK, AF_PACKET\n\n//SOCK constants (see `man socket` for more information)\n//SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, SOCK_RDM, SOCK_SEQPACKET\n\n\nstruct Socket\n{\n\t//connects to 'host':'port' using the first suitable protocol that can be specified\n\t//with 'family' (one of the AF_ constants) and 'socktype' (one of the SOCK_ constants)\n\tconstructor(host, port, family = AF_UNSPEC, socktype = SOCK_STREAM);\n\n\t//closes the connection\n\tdestructor();\n\n\tgetLocalAddress(buff); //puts the string representation of the local address into 'buff'\n\tgetRemoteAddress(buff); //puts the string representation of the remote address into 'buff'\n\n\t//check if data can be read (timeout in milliseconds)\n\t//negative timeout means infinite waiting\n\tavailable(timeout = 0);\n\n\tsend(buff, len); //send 'len' bytes from 'buff'\n\tsends(str); //send 'strlen(str)' bytes from 'str'\n\tsendc(byte); //send one byte\n\n\t//receive 'len' bytes, function will not return until 'len' bytes\n\t//were received or the remote closes the connection\n\t//returns count of bytes received\n\trecv(buff, len);\n\n\t//receive one byte\n\treadc();\n\n\t//read bytes into buff until:\n\t//\t- 'max' bytes were read\n\t//\t- 'end' byte is read\n\t//returns count of bytes read\n\tread(buff, max, end = 0);\n}:\n\nstruct SocketServer\n{\n\t//starts listening on port 'port'\n\t//\t- 'backlog' specifies the maximum number of pending connections\n\t//\t- 'family' should be one of the AF_* constants\n\t//\t- 'socktype' should be one of the SOCK_* constants\n\tconstructor(port, backlog = 16, family = AF_UNSPEC, socktype = SOCK_STREAM);\n\n\t//closes the server\n\tdestructor();\n\n\t//puts the string representation of the local address into 'buff'\n\tgetLocalAddress(buff);\n\n\t//waits for a pending connections 'timeout' milliseconds (negative means infinite)\n\t//returns an instance of 'Socket' or undefined if no client connected\n\taccept(timeout = -1);\n};\n\nstruct SocketSet\n{\n\tget count; //current length\n\tget capaticity; //current capaticity (autmatically increased when full and calling 'add')\n\n\tconstructor(startMax = 16); //'startMax' defines the starting capaticity\n\tdestructor(); //frees up the array of sockets\n\n\toperator foreach in this; //iterate over all Socket's and SocketServer's in the set\n\n\tadd(val); //add a Socket, SocketServer or file descriptor\n\tremove(value); //remove a value from the set\n\n\tcheck(timeout = -1); //wait for available data on one of the sockets and return that socket\n};\n```\n\n- `websocket.ptrs`\n```C\n//type passed to callbacks of a WebSocketServer, do not construct this yourself\nstruct libwebsock_client\n{\n\tuserdata : pointer; //can be used to store a pointer to your own data\n\n\tget server; //retrieve the WebSocketServer a client is connected to\n\n\tsend(text); //send text to the client\n\tsendBinary(buff, len); //send binary data to the client\n\tclose(); //close the connection to the client\n};\n\nstruct WebSocketServer\n{\n\tconstructor(port = \"6060\", host = \"0.0.0.0\"); //construct a new websocket server\n\n\t//the following callbacks are called when a client (dis-)connects or sends a message\n\t//\t'client' is of type libwebsock_client\n\tonopen; //arguments: (client)\n\tonclose; //arguments: (client)\n\tonmessage; //arguments: (client, message, len)\n\n\tuserdata = undefined; //can be used to store a pointer to your own data\n\n\tbroadcast(msg); //broadcasts msg to all connected clients\n\tlisten(); //starts listening, looping infinitly\n};\n```\n\n- `rcon.ptrs`:\n```C\nstruct Rcon\n{\n\terror;\n\tcontructor(host, port, password);\n\tcommand(cmd);\n\tend();\n}\n```\n\n- `mutex.ptrs`\n```C\nstruct MutexWrap\n{\n\tmutex{}; //memory for a pthread_mutex\n\n\t//\t'obj' will be thread-safely wrapped\n\t//\tif 'allowAddr' is false the \u0026this.key and \u0026this[key] will throw an exception\n\tconstructor(obj, allowAddr = false);\n\n\t//locks the mutex then gets/sets/calls the property of the wrapped object\n\toperator this.key;\n\toperator this[key];\n\toperator this.key = value;\n\toperator this[key] = value;\n\toperator \u0026this.key; //note: see 'allowAddr' above\n\toperator \u0026this[key]; //note: see 'allowAddr' above\n\toperator this.key(args...);\n\toperator this[key](args...);\n};\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm4gnv5%2Fptrsstuff","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fm4gnv5%2Fptrsstuff","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm4gnv5%2Fptrsstuff/lists"}