Skip to content

Commit

Permalink
rename ckb-lua to ckb-lua-vm
Browse files Browse the repository at this point in the history
  • Loading branch information
contrun committed Sep 25, 2023
1 parent e206c42 commit de9d067
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 51 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![CI](https://github.com/nervosnetwork/ckb-lua/actions/workflows/ci.yml/badge.svg)](https://github.com/nervosnetwork/ckb-lua/actions/workflows/ci.yml)
[![CI](https://github.com/nervosnetwork/ckb-lua-vm/actions/workflows/ci.yml/badge.svg)](https://github.com/nervosnetwork/ckb-lua-vm/actions/workflows/ci.yml)

# ckb-lua
# ckb-lua-vm
A project to help developers writing script in Lua on [CKB-VM](https://github.com/nervosnetwork/ckb-vm).


Expand Down Expand Up @@ -31,13 +31,13 @@ Use `build/lua-loader` as a script. Require hacking for further requirement.

## Command Line Arguments

A couple of arguments may be passed to ckb-lua.
If no command line arguments is passed to ckb-lua, ckb-lua will run the script contained in cell data,
A couple of arguments may be passed to ckb-lua-vm.
If no command line arguments is passed to ckb-lua-vm, ckb-lua-vm will run the script contained in cell data,
which is assumed to be a valid exectuable lua file.

The following are the supported command line arguments.
To test the `ADDITIONAL_ARGUMENTS` locally, we can run `ckb-debugger --bin ./build/lua-loader.debug -- ADDITIONAL_ARGUMENTS`

- `-e` is used to evaluate some lua script. For example, running `ckb-debugger --bin ./build/lua-loader.debug -- -e 'print("abcdefg")'` will print out `abcdefg` in to console.
- `-f` is used to enable [file system access](./docs/fs.md). For example, running `ckb-debugger --bin ./build/lua-loader.debug -- -f` would evaluate the `main.lua` file within the file system in the cell data.
- `-r` is used to execute coded loaded from ckb-debugger. For example, running `ckb-debugger ---read-file strings.lua --bin ./build/lua-loader.debug -- -r` will execute the lua file `strings.lua`. Normally, ckb-lua can not read files from local file system, we add this parameter (along with the `--read-file` parameter of `ckb-debugger`) to facilitate testing of running local lua files.
- `-r` is used to execute coded loaded from ckb-debugger. For example, running `ckb-debugger ---read-file strings.lua --bin ./build/lua-loader.debug -- -r` will execute the lua file `strings.lua`. Normally, ckb-lua-vm can not read files from local file system, we add this parameter (along with the `--read-file` parameter of `ckb-debugger`) to facilitate testing of running local lua files.
48 changes: 24 additions & 24 deletions docs/dylib.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/fs.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
To faciliate the sharing of lua modules, we created a file system called Simple Lua File System that can be mounted by ckb-lua.
To faciliate the sharing of lua modules, we created a file system called Simple Lua File System that can be mounted by ckb-lua-vm.
Files within the file system may be made available for lua scripts to read and execute,
e.g. running `require('mymodule')` and `io.open('myfile')`.
The file system can be stored in any cell whose data are reachable from lua scripts,
Expand Down
14 changes: 7 additions & 7 deletions docs/spawn.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ when the availablity of spawn syscall changes.
| mainnet | NOT ready |
| testnet | NOT ready |

# Running ckb-lua as a subprocess to the main script
There are quite a few benefits in running ckb-lua as a subprocess to the main script.
- The main script's context is saved, and can continue to run when ckb-lua exits.
- The ckb-lua instances are called with command line arguments which can be used to differentiate different tasks.
# Running ckb-lua-vm as a subprocess to the main script
There are quite a few benefits in running ckb-lua-vm as a subprocess to the main script.
- The main script's context is saved, and can continue to run when ckb-lua-vm exits.
- The ckb-lua-vm instances are called with command line arguments which can be used to differentiate different tasks.
- Ckb-lua may return data of any format by the function `ckb.set_content`.

To demostrate how to extend the capabilities of a main script with ckb-lua, we provide
an example (an admittedly contrived one) that spawn a ckb-lua subprocess which simply concatenate
To demostrate how to extend the capabilities of a main script with ckb-lua-vm, we provide
an example (an admittedly contrived one) that spawn a ckb-lua-vm subprocess which simply concatenate
the command line arguments and return the result to the main script.

[The main script of this example](../examples/spawn.c) is written in c.
This program can be built with `make all-via-docker`. Afterwards, you may run it
with `make -C tests/test_cases spawnexample` which requries [this branch of ckb-standalone-debugger](https://github.com/mohanson/ckb-standalone-debugger/tree/syscall_spawn).

The main script first reserves some memory for the sub-contract, and then invokes ckb-lua with
The main script first reserves some memory for the sub-contract, and then invokes ckb-lua-vm with
the command line arguments `"-e" "local m = arg[2] .. arg[3]; ckb.set_content(m)" "hello" "world"`
which evaluates the lua code `local m = arg[2] .. arg[3]; ckb.set_content(m)`.

Expand Down
4 changes: 2 additions & 2 deletions lua-loader/lua-ckb.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ int lua_ckb_exit(lua_State *L) {
int code = lua_get_int_code(L);
ckb_exit(code);
} else {
luaL_error(L, "exit in ckb-lua is not enabled");
luaL_error(L, "exit in ckb-lua-vm is not enabled");
}
return 0;
}
Expand Down Expand Up @@ -814,7 +814,7 @@ int lua_ckb_load_header_by_field(lua_State *L) {
}

int lua_ckb_spawn(lua_State *L) {
printf("spawn is currently not implementd in ckb-lua\n");
printf("spawn is currently not implementd in ckb-lua-vm\n");
lua_pushinteger(L, LUA_ERROR_NOT_IMPLEMENTED);
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cases/tests_rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/test_cases/tests_rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "ckb-lua-tests"
name = "ckb-lua-vm-tests"
version = "0.1.0"
authors = ["Nervos Core Dev <dev@nervos.org>"]
edition = "2021"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ fn debug_printer(script: &Byte32, msg: &str) {
fn gen_tx(dummy: &mut DummyDataLoader) -> TransactionView {
let mut rng = <StdRng as SeedableRng>::from_seed([42u8; 32]);

// setup lib_ckb_lua dep
let lib_ckb_lua_out_point = {
// setup lib_ckb_lua_vm dep
let lib_ckb_lua_vm_out_point = {
let contract_tx_hash = {
let mut buf = [0u8; 32];
rng.fill(&mut buf);
Expand All @@ -41,17 +41,17 @@ fn gen_tx(dummy: &mut DummyDataLoader) -> TransactionView {
OutPoint::new(contract_tx_hash, 0)
};
// dep contract code
let lib_ckb_lua_cell = CellOutput::new_builder()
let lib_ckb_lua_vm_cell = CellOutput::new_builder()
.capacity(
Capacity::bytes(LIB_CKB_LUA_BIN.len())
.expect("script capacity")
.pack(),
)
.build();
let lib_ckb_lua_cell_data_hash = CellOutput::calc_data_hash(&LIB_CKB_LUA_BIN);
let lib_ckb_lua_vm_cell_data_hash = CellOutput::calc_data_hash(&LIB_CKB_LUA_BIN);
dummy.cells.insert(
lib_ckb_lua_out_point.clone(),
(lib_ckb_lua_cell, LIB_CKB_LUA_BIN.clone()),
lib_ckb_lua_vm_out_point.clone(),
(lib_ckb_lua_vm_cell, LIB_CKB_LUA_BIN.clone()),
);

// setup dylib_test dep
Expand Down Expand Up @@ -86,7 +86,7 @@ fn gen_tx(dummy: &mut DummyDataLoader) -> TransactionView {
.dep_type(DepType::Code.into())
.build(),
CellDep::new_builder()
.out_point(lib_ckb_lua_out_point)
.out_point(lib_ckb_lua_vm_out_point)
.dep_type(DepType::Code.into())
.build(),
])
Expand All @@ -104,9 +104,9 @@ fn gen_tx(dummy: &mut DummyDataLoader) -> TransactionView {
};
let out_point = OutPoint::new(previous_tx_hash, 0);

let mut buf = BytesMut::with_capacity(2 + lib_ckb_lua_cell_data_hash.as_slice().len() + 1);
let mut buf = BytesMut::with_capacity(2 + lib_ckb_lua_vm_cell_data_hash.as_slice().len() + 1);
buf.extend_from_slice(&[0x00u8; 2]);
buf.extend_from_slice(lib_ckb_lua_cell_data_hash.as_slice());
buf.extend_from_slice(lib_ckb_lua_vm_cell_data_hash.as_slice());
buf.put_u8(ScriptHashType::Data1.into());
let args = buf.freeze();

Expand Down
2 changes: 1 addition & 1 deletion tests/test_cases/tests_rust/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod lib_ckb_lua;
mod lib_ckb_lua_vm;

use ckb_traits::{CellDataProvider, HeaderProvider};
use ckb_types::{
Expand Down

0 comments on commit de9d067

Please sign in to comment.