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.
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 |
Enum
Requires a instance of self.
This function can return a Exception and should be caught.
This is a Getter.
This is a Setter.
HTTP Version
HTTP_VERSION_1_1 = 0
HTTP_VERSION_2 = 1
HTTP_VERSION_3 = 2
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`
Paramaters are:
Returns: pxs_List[pxs_List[pxs_String]]
The headers.
Paramaters are:
Returns: pxs_String value if found.
Get a single header.
Paramaters are:
Set a single header.
Paramaters are:
Returns: pxs_String
Paramaters are:
Returns: pxs_Int64
Version
Paramaters are:
Returns: pxs_String
Domain name
Paramaters are:
Returns: pxs_Int64
Tiemout in MS
Paramaters are:
Returns: pxs_String
Make a request
Paramaters are:
Returns: pxs_Bool
Use HTTPS.
Paramaters are:
Returns: http-ClientResponse
Make a HTTP Post request.
Paramaters are:
Delete a
from pxs import mem
from pxs import Logger
l = Logger()
mem.memdel(l)
Paramaters are:
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])
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:
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.
Paramaters are:
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:
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:
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:
Returns: pxs_Bool
Check if a path exists
from pxs import fs
fs.exists("test.txt")
Paramaters are:
Returns: pxs_Bool
Check if is a directory.
from pxs import fs
fs.is_dir("test")
Paramaters are:
Returns: pxs_Bool
Check if is a file
from pxs import fs
fs.is_file("test")
Paramaters are:
Write to a file.
from pxs import fs
fs.write_file("test.txt", "dude!")
Paramaters are:
Append to a file.
from pxs import fs
fs.append_file("test.txt", "dude!")
Paramaters are:
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:
Create a directory.
from pxs import fs
fs.create_dir("test")
Paramaters are:
Create a directory recursively
from pxs import fs
fs.create_dirs("test/test2/test3")
Paramaters are:
Remove a empty directory
from pxs import fs
fs.remove_empty_dir("test/test2/test3")
Paramaters are:
Remove a directory, regardless of emptyness.
from pxs import fs
fs.remove_dir("test")
Paramaters are:
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)
Returns: pxs_String
Get the current working directory
from pxs import print, os
print(os.get_cwd())
Paramaters are:
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:
Returns: pxs_String
Read a enviroment variable.
from pxs import os, print
print(os.read_env('name'))
Paramaters are:
Set a enviroment variable.
from pxs import os, print
os.set_env('name', 'Evelyn chan')
print(os.read_env('name'))
Just a wrapper around Output
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:
Returns: Shell
Create a new shell.
Define this as a command. Only call this once before adding any args after program.
Paramaters are:
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:
Returns: pxs_Int64 the status code.
Run a command. Prints to terminal by default.
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.
Paramaters are:
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:
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:
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:
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:
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:
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]))