CoreLib

Pixelscript comes with an optional core library modules. They sit behind the pxs module.

To use the core library you must run pxs_core_initall(). Or you can initialize specific modules.


Specific Modules

There are specific modules in pixelscript that can be added or not.

Module Enum Value
pxs.mem pxs_ModuleFlag::pxs_MEM 2
pxs.os pxs_ModuleFlag::pxs_OS 4
pxs pxs_ModuleFlag::pxs_PXS 8
pxs.fs pxs_ModuleFlag::pxs_FS 16
pxs.shell pxs_ModuleFlag::pxs_SHELL 32
pxs.zip pxs_ModuleFlag::pxs_ZIP 64
pxs.http pxs_ModuleFlag::pxs_HTTP 128
pxs.cross pxs_ModuleFlag::pxs_CROSS 128

What the circles mean

Enum

Requires a instance of self.

This function can return a Exception and should be caught.

This is a Getter.

This is a Setter.


pxs.http

HTTP Version

HTTP_VERSION_1_1 = 0

HTTP_VERSION_2 = 1

HTTP_VERSION_3 = 2

http-ClientResponse

Returns: pxs_Int64

The response status.

Returns: pxs_List[pxs_Byte]

The response bytes.

Returns: pxs_String

The response text.

Returns: http-Client

Create a new #`http-Client`

http-Client

Paramaters are:

  1. headers: pxs_List[pxs_List[pxs_String]] the headers to set.))

Returns: pxs_List[pxs_List[pxs_String]]

The headers.

Paramaters are:

  1. key: pxs_String the header key.))

Returns: pxs_String value if found.

Get a single header.

Paramaters are:

  1. key: pxs_String header key)
  2. value: pxs_String header value))

Set a single header.

Paramaters are:

  1. body: pxs_String|pxs_List[pxs_Byte] body as string or bytes.))

Returns: pxs_String

Paramaters are:

  1. version: pxs_Int64 the http version to use.))

Returns: pxs_Int64

Version

Paramaters are:

  1. dn: pxs_String the domain name))

Returns: pxs_String

Domain name

Paramaters are:

  1. ms: pxs_Int64 millisecond))

Returns: pxs_Int64

Tiemout in MS

Paramaters are:

  1. url: pxs_String the url to request)
  2. rt: pxs_Int64 the request type to send.))

Returns: pxs_String

Make a request

Paramaters are:

  1. use: pxs_Bool true for using. false for not.))

Returns: pxs_Bool

Use HTTPS.

Paramaters are:

  1. url: pxs_String the url to request to)
  2. body: pxs_String the body to send)
  3. headers: @opt pxs_List[pxs_List[pxs_String]] the headers to apply)
  4. version: @opt pxs_Int64 the HTTP version to use))

Returns: http-ClientResponse

Make a HTTP Post request.


pxs.mem

Paramaters are:

  1. object: pxs_Object the object to delete. Must contain <_pxs_ptr>)).

Delete a s .

                
from pxs import mem
from pxs import Logger
l = Logger()
mem.memdel(l)
                
            

Paramaters are:

  1. objects: pxs_List[pxs_Object] a list of object that have assigned.))

Delete a List of `pxs_Var` `PixelObject`

                
from pxs import mem
from pxs import Logger

l1 = Logger()
l2 = Logger()
l3 = Logger()

mem.mem_delall([l1, l2, l3])
                
            

pxs.fs

How to read a file. Pass in `read_file`.

Text = 1

Bytes = 2

How to open a file. Pass in `File`.

Read = 1 << 0

Write = 1 << 1

Append = 1 << 2

Access to a File.

Our pxs exposed File object

Paramaters are:

  1. path: pxs_String path to the file.)
  2. open_file: pxs_Int64 open file type. Defaults to READ.))

Returns: fs-File

Open or create a new #`fs-File`.

open_file is defaulted to Read if not passed.

                
from pxs import fs
f = fs.File("text.txt", fs.OPEN_TYPE_WRITE)
f.write('test')
f.close() # remember to close your files.
                
            
fs-File

Paramaters are:

  1. contents: pxs_String|pxs_List[pxs_Byte] the contents to write. It can either be a string or a list of bytes.))

Write some file.

                
from pxs import fs
from pxs import print
f = fs.File("test.txt", fs.OPEN_TYPE_WRITE)
f.write("test")
print(fs.read_file('test.txt'))
                
            

Paramaters are:

  1. read_type: pxs_Int64 how do we read the file. Should we return a pxs_String or pxs_List[pxs_Byte]))

Returns: pxs_String|pxs_List[pxs_Byte]

Read

TODO(jc) return num bytes read, make it possible to read up to a certain number at a time.

                
from pxs import fs
f = fs.File("test.txt", fs.OPEN_TYPE_READ)
contents = f.read()
                
            

Returns: pxs_String

Path prop

Returns: pxs_Int64

Open type prop

Close the file.

                
from pxs import fs
from pxs import print
f = fs.File("new.py", fs.OPEN_TYPE_WRITE | fs.OPEN_TYPE_READ)
f.write('print(1 + 1)')
print(f.read())
f.close() # can not use File operations after this.
                
            

Paramaters are:

  1. file_path: pxs_String the path to said file.)
  2. read_type: pxs_Int64 how to return the contents.))

Returns: pxs_String|pxs_List[pxs_Byte]

Read a file, returns either a pxs_String, or pxs_List of pxs_Byte.

                
from pxs import fs
fs.read_file("test.txt")
                
            

Paramaters are:

  1. path: pxs_String path to file.))

Returns: pxs_Bool

Check if a path exists

                
from pxs import fs
fs.exists("test.txt")
                
            

Paramaters are:

  1. path: pxs_String path to directory))

Returns: pxs_Bool

Check if is a directory.

                
from pxs import fs
fs.is_dir("test")
                
            

Paramaters are:

  1. path: pxs_String path to directory))

Returns: pxs_Bool

Check if is a file

                
from pxs import fs
fs.is_file("test")
                
            

Paramaters are:

  1. path: pxs_String file path)
  2. contents: pxs_String|pxs_List[pxs_Byte] file contents))

Write to a file.

                
from pxs import fs
fs.write_file("test.txt", "dude!")
                
            

Paramaters are:

  1. path: pxs_String file path)
  2. contents: pxs_String|pxs_List[pxs_Byte] file contents))

Append to a file.

                
from pxs import fs
fs.append_file("test.txt", "dude!")
                
            

Paramaters are:

  1. path: pxs_String file path))

Remove a file

                
from pxs import fs, print
fs.write_file("test.txt", "contents")
print(fs.read_file("test.txt"))
fs.remove_file("test.txt")
print(fs.exists("test.txt"))
                
            

Paramaters are:

  1. path: pxs_String path to directory))

Create a directory.

                
from pxs import fs
fs.create_dir("test")
                
            

Paramaters are:

  1. path: pxs_String path to directory))

Create a directory recursively

                
from pxs import fs
fs.create_dirs("test/test2/test3")
                
            

Paramaters are:

  1. path: pxs_String path to directory))

Remove a empty directory

                
from pxs import fs
fs.remove_empty_dir("test/test2/test3")
                
            

Paramaters are:

  1. path: pxs_String path to directory))

Remove a directory, regardless of emptyness.

                
from pxs import fs
fs.remove_dir("test")
                
            

Paramaters are:

  1. path: pxs_String path to directory))

Returns: pxs_List[pxs_String]

Read contents of directory.

                
from pxs import fs
from pxs import print
dir = fs.read_dir("test")
for item in dir:
    print(item)
                
            

pxs.os

Returns: pxs_String

Get the current working directory

                
from pxs import print, os
print(os.get_cwd())
                
            

Paramaters are:

  1. path: pxs_String new directory))

Change the current directory

                
from pxs import print, os, fs
print(os.get_cwd())
fs.create_dir('example')
os.chdir("example")
print(os.get_cwd())
                
            

Paramaters are:

  1. key: pxs_String the key to read))

Returns: pxs_String

Read a enviroment variable.

                
from pxs import os, print
print(os.read_env('name'))
                
            

Paramaters are:

  1. key: pxs_String the key to set)
  2. value: pxs_String the value))

Set a enviroment variable.

                
from pxs import os, print
os.set_env('name', 'Evelyn chan')
print(os.read_env('name'))
                
            

pxs.shell

Just a wrapper around Output

ShellOutput

Returns: pxs_String

Get stdout

Returns: pxs_String

Get stderr

Returns: pxs_Int64

Get status

Just a wrapper around Command.

Returns: Shell

Create a new platform shell.

Paramaters are:

  1. program: pxs_String the starting program))

Returns: Shell

Create a new shell.

Shell

Define this as a command. Only call this once before adding any args after program.

arg

Paramaters are:

  1. argument: pxs_String the argument))

Add a argument to the command.

Returns: pxs_Int64

Run and get status code.

Spawn a process.

Returns: ShellOutput

Run and get output as a `Output`.

Paramaters are:

  1. command: pxs_String the command to run.))

Returns: pxs_Int64 the status code.

Run a command. Prints to terminal by default.


pxs.cross

Determines what the #`RuntimeObject` can and can not do.

Runtime = [_call, _exec, _eval, _get, _set].

Function = [_call]

Object = [_call, _get, _set]

Runtime = 0

Function = 1

Object = 2

A value from another runtime. Each `RuntimeObject` operates differently. See #`RuntimeObjectType` for more details.

RuntimeObject

Paramaters are:

  1. name: pxs_String|pxs_List Can be either the name or args if calling itself.)
  2. args: pxs_List? arguments of the function. Is only null when passing args as name.))

Returns: RuntimeObject|pxs_Va

Depending on the `type`, it will either call a function or call itself.

If `type` is Runtime, it will call a function.

If `type` is Function, it will call itself.

If `type` is Object, it will call a property of itself.

                
from pxs import print
from pxs.cross import access

lua = access(0)
lua._exec("function add(n1, n2) return n1 + n2 end")
add = lua._get('add')
print(add._call([1,2]))
                
            

Paramaters are:

  1. name: pxs_String the name of the variable.))

Returns: RuntimeObject|pxs_Va The result of the get.

Get a variable/object/function.

If `type` is Runtime, it will get from global scope.

If `type` is Object, it will get a property of itself.

                
from pxs import print
from pxs.cross import access
js = access(2)
js._exec("""
    globalThis.Me = {
        name: "Jordan"
    };
""")

js_me = js._get('Me')
print(js_me._get('name'))
                
            

Paramaters are:

  1. key: pxs_String the name of the variable.)
  2. value: pxs_Var a value.))

Get a variable/object/function.

Only on `type` Object.

                
from pxs import print
from pxs.cross import access
js = access(2)
js._exec("""
    globalThis.Me = {
        name: "Jordan"
    };
""")

js_me = js._get('Me')
js_me._set('name', 'Jordan Castro')
print(js_me._get('name'))
                
            

Paramaters are:

  1. code: pxs_String the code to execute.)
  2. file_name: pxs_String optional name for debugging.))

Returns: pxs_String string if a exception occured.

Execute arbitrary code in the runtime.

Only on `type` Runtime.

                
from pxs import print
from pxs.cross import access
py = access(1)
py._exec("print('hello!')")
                
            

Paramaters are:

  1. code: pxs_String the code to evaluate.)
  2. file_name: pxs_String optional name for debugging.))

Returns: pxs_Var The result of the evaluation. If a exception is thrown in the evaluation, it is also thrown in the current runtime and it must be caught.

Evaluate arbitrary code in the runtime.

Only on `type` Runtime.

                
from pxs import print
from pxs.cross import access
js = access(2)
result = js._eval('1 + 1')
print(result)
                
            

Paramaters are:

  1. rt: pxs_Int64 the runtime value.))

Returns: RuntimeObject access to the runtime.

Access a pxs runtime via scripting.

                
from pxs.cross import access
from pxs import print
lua = access(0)
lua._exec(" function add(n1,n2) return n1 + n2 end ")
print(lua._call('add', [1,2]))