diff --git a/README.md b/README.md index 235f20e..79f434a 100644 --- a/README.md +++ b/README.md @@ -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). @@ -28,3 +28,16 @@ Use `build/libckblua.so` as a dynamic library. See [dylib.md](./docs/dylib.md) f 2. Standalone 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-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-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. diff --git a/docs/dylib.md b/docs/dylib.md index 325a85e..1ecc2e2 100644 --- a/docs/dylib.md +++ b/docs/dylib.md @@ -2,7 +2,7 @@ To facilitate the development of contracts on ckb platform, we recently ported Lua, a scripting language famous for its simplicity and ease of use, to the ckb-vm. Ckb developers can now both run the standalone Lua interpreter in the ckb platform and embed Lua code into their main ckb contracts. This greatly lower the barrier to entry for ckb contracts development. -[dylib.c](https://github.com/XuJiandong/ckb-lua/blob/70bc3e7bff3521a600612e52b9a2aee56c3efca2/examples/dylib.c) a sample program that evaluates lua code with ckb-lua shared library. We showcase how to load and unpack script args by a few lines of Lua code, i.e. +[dylib.c](https://github.com/nervosnetwork/ckb-lua-vm/blob/70bc3e7bff3521a600612e52b9a2aee56c3efca2/examples/dylib.c) a sample program that evaluates lua code with ckb-lua-vm shared library. We showcase how to load and unpack script args by a few lines of Lua code, i.e. ```lua local _code_hash, _hash_type, args, err = ckb.load_and_unpack_script() @@ -12,19 +12,19 @@ if err == nil then end ``` -Of course, this example is not enough for real world usage, but this article should be enough to show how to use ckb-lua shared library from the main contract program. You can unleash the potential of Lua with your creativity afterward. For the curious, see here for [an implementation of sudt in lua](https://github.com/XuJiandong/ckb-lua/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/contracts/sudt.lua). Also note that, the sample code is written in c. As an alternative, you can write test code in rust. Both [loading shared library](https://docs.rs/ckb-std/latest/ckb_std/dynamic_loading/index.html) and mocking transaction to do unit tests are easy in rust. +Of course, this example is not enough for real world usage, but this article should be enough to show how to use ckb-lua-vm shared library from the main contract program. You can unleash the potential of Lua with your creativity afterward. For the curious, see here for [an implementation of sudt in lua](https://github.com/nervosnetwork/ckb-lua-vm/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/contracts/sudt.lua). Also note that, the sample code is written in c. As an alternative, you can write test code in rust. Both [loading shared library](https://docs.rs/ckb-std/latest/ckb_std/dynamic_loading/index.html) and mocking transaction to do unit tests are easy in rust. I will now explain what this sample code does and how to run it. # Building Shared Library -The sample code depends on `libckblua.so` shared library to run Lua code. We need to obtain the source of ckb-lua from [the github repository](https://github.com/XuJiandong/ckb-lua), and build it ourselves. `make all-via-docker` is enough to build all the binaries. `./build/libckblua.so` may be used afterward. The sample program `./build/dylibexample` built from [dylib.c](https://github.com/XuJiandong/ckb-lua/blob/70bc3e7bff3521a600612e52b9a2aee56c3efca2/examples/dylib.c) is also available to use. +The sample code depends on `libckblua.so` shared library to run Lua code. We need to obtain the source of ckb-lua-vm from [the github repository](https://github.com/nervosnetwork/ckb-lua-vm), and build it ourselves. `make all-via-docker` is enough to build all the binaries. `./build/libckblua.so` may be used afterward. The sample program `./build/dylibexample` built from [dylib.c](https://github.com/nervosnetwork/ckb-lua-vm/blob/70bc3e7bff3521a600612e52b9a2aee56c3efca2/examples/dylib.c) is also available to use. # Preparing Shared Library ## Packing the Shared Library Into the Dependent Cell Data -To use the ckb-lua shared library, we need to store the shared library in some cell data and specify the cell with shared library data as a dependent cell. We have assembled a [mock transaction file](https://crates.io/crates/ckb-mock-tx-types) [here](https://github.com/XuJiandong/ckb-lua/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/tests/test_cases/dylib.json). You can also mock this with the ckb rust SDK (like [this](https://github.com/nervosnetwork/ckb-production-scripts/blob/master/tests/xudt_rce_rust/tests/test_xudt_rce.rs)). You can use it along with [ckb-standalone-debugger](https://github.com/nervosnetwork/ckb-standalone-debugger) to run the sample code. For example, you can run `./build/dylibexample` with `ckb-debugger --tx-file ./tests/test_cases/dylib.json --script-group-type=type --cell-index=0 --cell-type=output --bin build/dylibexample`. +To use the ckb-lua-vm shared library, we need to store the shared library in some cell data and specify the cell with shared library data as a dependent cell. We have assembled a [mock transaction file](https://crates.io/crates/ckb-mock-tx-types) [here](https://github.com/nervosnetwork/ckb-lua-vm/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/tests/test_cases/dylib.json). You can also mock this with the ckb rust SDK (like [this](https://github.com/nervosnetwork/ckb-production-scripts/blob/master/tests/xudt_rce_rust/tests/test_xudt_rce.rs)). You can use it along with [ckb-standalone-debugger](https://github.com/nervosnetwork/ckb-standalone-debugger) to run the sample code. For example, you can run `./build/dylibexample` with `ckb-debugger --tx-file ./tests/test_cases/dylib.json --script-group-type=type --cell-index=0 --cell-type=output --bin build/dylibexample`. ## Passing the Dependent Cell Information with Script Args @@ -86,9 +86,9 @@ Calling `lua_close_instance` will release all the resources used by Lua. It take ### Functions in Lua Standard Library -Most of the functions in Lua standard library have been ported to ckb-lua. You can expect all the platform-independent functions to work. But some platform-dependent functions (e.g. all functions in the module `os`) are not provided in ckb-lua. +Most of the functions in Lua standard library have been ported to ckb-lua-vm. You can expect all the platform-independent functions to work. But some platform-dependent functions (e.g. all functions in the module `os`) are not provided in ckb-lua-vm. -TODO: add list of functions that are not available in ckb-lua. +TODO: add list of functions that are not available in ckb-lua-vm. ### CKB Specific Functions @@ -142,7 +142,7 @@ loads the ckb script and unpacks it into `code_hash`, `hash_type` and `args`. If # Request for Comments -The prototype of ckb-lua is now somewhat complete. We are now gathering feedback on the usage of ckb-lua. If you have any use cases that are not easily met by the current ckb-lua implementation in mind, please feel free to leave comments at the [ckb-lua](https://github.com/XuJiandong/ckb-lua) repository. +The prototype of ckb-lua-vm is now somewhat complete. We are now gathering feedback on the usage of ckb-lua-vm. If you have any use cases that are not easily met by the current ckb-lua-vm implementation in mind, please feel free to leave comments at the [ckb-lua-vm](https://github.com/nervosnetwork/ckb-lua-vm) repository. # Appendix: Exported Lua Functions and Constants in the CKB Module @@ -169,7 +169,7 @@ Most of they may return an error as the last argument. The error is a non-zero i ### More Examples -[See ckb syscall test cases](https://github.com/XuJiandong/ckb-lua/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/tests/test_cases/test_ckbsyscalls.lua). +[See ckb syscall test cases](https://github.com/nervosnetwork/ckb-lua-vm/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/tests/test_cases/test_ckbsyscalls.lua). ### Functions @@ -179,7 +179,7 @@ Note when partial loading support is enabled, the description for arguments leng #### `ckb.dump` description: dump a returned buffer to stdout -calling example: [`ckb.dump(buf)`](https://github.com/XuJiandong/ckb-lua/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/tests/test_cases/test_ckbsyscalls.lua#L101-L105) +calling example: [`ckb.dump(buf)`](https://github.com/nervosnetwork/ckb-lua-vm/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/tests/test_cases/test_ckbsyscalls.lua#L101-L105) arguments: buf (a buffer returned from syscalls below) @@ -227,7 +227,7 @@ see also: [file system documentation](./fs.md) #### `ckb.load_tx_hash` description: load the transaction hash -calling example: [`buf, err = ckb.load_tx_hash()`](https://github.com/XuJiandong/ckb-lua/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/tests/test_cases/test_ckbsyscalls.lua#L51-L53) +calling example: [`buf, err = ckb.load_tx_hash()`](https://github.com/nervosnetwork/ckb-lua-vm/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/tests/test_cases/test_ckbsyscalls.lua#L51-L53) arguments: none @@ -240,7 +240,7 @@ see also: [`ckb_load_tx_hash` syscall](https://github.com/nervosnetwork/rfcs/blo #### `ckb.load_script_hash` description: load the hash of current script -calling example: [`buf, error = ckb.load_script_hash()`](https://github.com/XuJiandong/ckb-lua/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/tests/test_cases/test_ckbsyscalls.lua#L63-L65) +calling example: [`buf, error = ckb.load_script_hash()`](https://github.com/nervosnetwork/ckb-lua-vm/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/tests/test_cases/test_ckbsyscalls.lua#L63-L65) arguments: none @@ -253,7 +253,7 @@ see also: [`ckb_load_script_hash` syscall](https://github.com/nervosnetwork/rfcs #### `ckb.load_script` description: load current script -calling example: [`buf, error = ckb.load_script()`](https://github.com/XuJiandong/ckb-lua/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/tests/test_cases/test_ckbsyscalls.lua#L59-L61) +calling example: [`buf, error = ckb.load_script()`](https://github.com/nervosnetwork/ckb-lua-vm/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/tests/test_cases/test_ckbsyscalls.lua#L59-L61) arguments: none @@ -266,7 +266,7 @@ see also: [`ckb_load_script` syscall](https://github.com/nervosnetwork/rfcs/blob #### `ckb.load_and_unpack_script` description: load and unpack current script -calling example: [`code_hash, hash_type, args, error = ckb.load_and_unpack_script()`](https://github.com/XuJiandong/ckb-lua/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/tests/test_cases/test_ckbsyscalls.lua#L172-L176) +calling example: [`code_hash, hash_type, args, error = ckb.load_and_unpack_script()`](https://github.com/nervosnetwork/ckb-lua-vm/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/tests/test_cases/test_ckbsyscalls.lua#L172-L176) arguments: none @@ -275,7 +275,7 @@ return values: code_hash (the code hash of current script), hash_type (the hash #### `ckb.load_transaction` description: load current transaction -calling example: [`buf, error = ckb.load_transaction()`](https://github.com/XuJiandong/ckb-lua/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/tests/test_cases/test_ckbsyscalls.lua#L55-L57) +calling example: [`buf, error = ckb.load_transaction()`](https://github.com/nervosnetwork/ckb-lua-vm/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/tests/test_cases/test_ckbsyscalls.lua#L55-L57) arguments: none @@ -288,7 +288,7 @@ see also: [`ckb_load_transaction` syscall](https://github.com/nervosnetwork/rfcs #### `ckb.load_cell` description: load cell -calling example: [`buf, error = ckb.load_cell(index, source)`](https://github.com/XuJiandong/ckb-lua/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/tests/test_cases/test_ckbsyscalls.lua#L67-L73) +calling example: [`buf, error = ckb.load_cell(index, source)`](https://github.com/nervosnetwork/ckb-lua-vm/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/tests/test_cases/test_ckbsyscalls.lua#L67-L73) arguments: index (the index of the cell), source (the source of the cell) @@ -301,7 +301,7 @@ see also: [`ckb_load_cell` syscall](https://github.com/nervosnetwork/rfcs/blob/m #### `ckb.load_input` description: load input cell -calling example: [`buf, error = ckb.load_input(index, source)`](https://github.com/XuJiandong/ckb-lua/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/tests/test_cases/test_ckbsyscalls.lua#L143-L145) +calling example: [`buf, error = ckb.load_input(index, source)`](https://github.com/nervosnetwork/ckb-lua-vm/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/tests/test_cases/test_ckbsyscalls.lua#L143-L145) arguments: index (the index of the cell), source (the source of the cell) @@ -314,7 +314,7 @@ see also: [`ckb_load_input` syscall](https://github.com/nervosnetwork/rfcs/blob/ #### `ckb.load_header` description: load cell header -calling example: [`buf, error = ckb.load_header(index, source)`](https://github.com/XuJiandong/ckb-lua/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/tests/test_cases/test_ckbsyscalls.lua#L160-L163) +calling example: [`buf, error = ckb.load_header(index, source)`](https://github.com/nervosnetwork/ckb-lua-vm/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/tests/test_cases/test_ckbsyscalls.lua#L160-L163) arguments: index (the index of the cell), source (the source of the cell) @@ -327,7 +327,7 @@ see also: [`ckb_load_header` syscall](https://github.com/nervosnetwork/rfcs/blob #### `ckb.load_witness` description: load the witness -calling example: [`buf, error = ckb.load_witness(index, source, length, offset)`](https://github.com/XuJiandong/ckb-lua/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/tests/test_cases/test_ckbsyscalls.lua#L3-L49) +calling example: [`buf, error = ckb.load_witness(index, source, length, offset)`](https://github.com/nervosnetwork/ckb-lua-vm/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/tests/test_cases/test_ckbsyscalls.lua#L3-L49) arguments: index (the index of the cell), source (the source of the cell) @@ -340,7 +340,7 @@ see also: [`ckb_load_witness` syscall](https://github.com/nervosnetwork/rfcs/blo #### `ckb.load_cell_data` description: load cell data -calling example: [`buf, error = ckb.load_cell_data(index, source, length, offset)`](https://github.com/XuJiandong/ckb-lua/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/tests/test_cases/test_ckbsyscalls.lua#L135-L141) +calling example: [`buf, error = ckb.load_cell_data(index, source, length, offset)`](https://github.com/nervosnetwork/ckb-lua-vm/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/tests/test_cases/test_ckbsyscalls.lua#L135-L141) arguments: index (the index of the cell), source (the source of the cell) @@ -353,7 +353,7 @@ see also: [`ckb_load_cell_data` syscall](https://github.com/nervosnetwork/rfcs/b #### `ckb.load_cell_by_field` description: load cell data field -calling example: [`buf, error = ckb.load_cell_by_field(index, source, field)`](https://github.com/XuJiandong/ckb-lua/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/tests/test_cases/test_ckbsyscalls.lua#L75-L133) +calling example: [`buf, error = ckb.load_cell_by_field(index, source, field)`](https://github.com/nervosnetwork/ckb-lua-vm/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/tests/test_cases/test_ckbsyscalls.lua#L75-L133) arguments: index (the index of the cell), source (the source of the cell), field (the field to load) @@ -366,7 +366,7 @@ see also: [`ckb_load_cell_by_field` syscall](https://github.com/nervosnetwork/rf #### `ckb.load_input_by_field` description: load input field -calling example: [`buf, error = ckb.load_input_by_field(index, source, field)`](https://github.com/XuJiandong/ckb-lua/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/tests/test_cases/test_ckbsyscalls.lua#L147-L155) +calling example: [`buf, error = ckb.load_input_by_field(index, source, field)`](https://github.com/nervosnetwork/ckb-lua-vm/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/tests/test_cases/test_ckbsyscalls.lua#L147-L155) arguments: index (the index of the cell), source (the source of the cell), field (the field to load) @@ -379,7 +379,7 @@ see also: [`ckb_load_input_by_field` syscall](https://github.com/nervosnetwork/r #### `ckb.load_header_by_field` description: load header by field -calling example: [`ckb.load_header_by_field(index, source, field)`](https://github.com/XuJiandong/ckb-lua/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/tests/test_cases/test_ckbsyscalls.lua#L157-L170) +calling example: [`ckb.load_header_by_field(index, source, field)`](https://github.com/nervosnetwork/ckb-lua-vm/blob/4e5375eb2a866595f89826db5510bc9d1f8e9510/tests/test_cases/test_ckbsyscalls.lua#L157-L170) arguments: index (the index of the cell), source (the source of the cell), field (the field to load) @@ -392,7 +392,7 @@ see also: [`ckb_load_header_by_field` syscall](https://github.com/nervosnetwork/ #### `ckb.unpack_script` description: unpack the buffer that contains the molecule structure `Script` -calling example: [`ckb.unpack_script(buf)`](https://github.com/contrun/ckb-lua/blob/4c05beeaa679acfd0b5e8d24e6c012374f08f11b/tests/test_cases/test_ckbsyscalls.lua#L191C56-L195) +calling example: [`ckb.unpack_script(buf)`](https://github.com/contrun/ckb-lua-vm/blob/4c05beeaa679acfd0b5e8d24e6c012374f08f11b/tests/test_cases/test_ckbsyscalls.lua#L191C56-L195) arguments: buf (the buffer that contains the molecule structure `Script`) @@ -457,7 +457,7 @@ see also: [The molecule definition of `CellDep`](https://github.com/nervosnetwor ## Exported constants -While most constants here are directly taken from [ckb_consts.h](https://github.com/nervosnetwork/ckb-system-scripts/blob/master/c/ckb_consts.h), we also defined some are ckb-lua specific constants like `ckb.LUA_ERROR_INTERNAL`. +While most constants here are directly taken from [ckb_consts.h](https://github.com/nervosnetwork/ckb-system-scripts/blob/master/c/ckb_consts.h), we also defined some are ckb-lua-vm specific constants like `ckb.LUA_ERROR_INTERNAL`. ``` ckb.SUCCESS diff --git a/docs/fs.md b/docs/fs.md index 004ef80..9dd2deb 100644 --- a/docs/fs.md +++ b/docs/fs.md @@ -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, diff --git a/docs/spawn.md b/docs/spawn.md index 599c010..727da83 100644 --- a/docs/spawn.md +++ b/docs/spawn.md @@ -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)`. diff --git a/lua-loader/lua-cell-fs.c b/lua-loader/lua-cell-fs.c index dcf5245..2d78864 100644 --- a/lua-loader/lua-cell-fs.c +++ b/lua-loader/lua-cell-fs.c @@ -1,6 +1,2 @@ #include "../include/ckb_cell_fs.c" #include "lua-cell-fs-test.c" - -static int run_from_file_system(lua_State *L) { - return run_file_system_tests(L); -} diff --git a/lua-loader/lua-ckb.c b/lua-loader/lua-ckb.c index fb60e6b..a546e74 100644 --- a/lua-loader/lua-ckb.c +++ b/lua-loader/lua-ckb.c @@ -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; } @@ -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; } diff --git a/lua-loader/lua-loader.c b/lua-loader/lua-loader.c index a8805ce..ce8eabb 100644 --- a/lua-loader/lua-loader.c +++ b/lua-loader/lua-loader.c @@ -326,7 +326,6 @@ static int pushargs(lua_State *L) { #define has_r 4 /* -r, to run scripts, with ability to load local files */ #define has_f 16 /* -f, to enable file system support */ #define has_t 32 /* -t, for file system tests */ -#define has_l 64 /* -l, to run scripts, without ability to load local files */ /* ** Traverses all arguments from 'argv', returning a mask with those ** needed before running any Lua code (or an error code if it finds @@ -347,9 +346,6 @@ static int collectargs(char **argv, int *first) { case 'r': args |= has_r; break; - case 'l': - args |= has_l; - break; case 'f': args |= has_f; break; @@ -378,10 +374,9 @@ int read_file(char *buf, int size) { return ret; } -// Load the file given from syscall, may optionally enable access to local files -// by setting local_access_enabled to non-zero. -static int run_from_file(lua_State *L, int local_access_enabled) { - enable_local_access(local_access_enabled); +// Load the file given from syscall. +static int run_from_file(lua_State *L) { + enable_local_access(1); char buf[1024 * 512]; int count = read_file(buf, sizeof(buf)); if (count < 0 || count == sizeof(buf)) { @@ -448,11 +443,11 @@ static int pmain(lua_State *L) { } if (args & has_t) { enable_fs_access(1); - ret = run_from_file_system(L); + ret = run_file_system_tests(L); goto exit; } - if (args & has_r || args & has_l) { - ret = run_from_file(L, (args & has_r) == has_r); + if (args & has_r) { + ret = run_from_file(L); goto exit; } ret = load_lua_code_from_cell_data(L); diff --git a/tests/official/main.lua b/tests/official/main.lua index 9def638..20e142b 100644 --- a/tests/official/main.lua +++ b/tests/official/main.lua @@ -443,7 +443,7 @@ NoRun("unrecognized option '-vv'", "lua -vv") NoRun("unrecognized option '-iv'", "lua -iv") NoRun("'-e' needs argument", "lua -e") NoRun("syntax error", "lua -e a") -NoRun("'-l' needs argument", "lua -l") +-- NoRun("'-l' needs argument", "lua -l") if T then -- test library? diff --git a/tests/test_cases/tests_rust/Cargo.lock b/tests/test_cases/tests_rust/Cargo.lock index 23bec4a..ba8b75e 100644 --- a/tests/test_cases/tests_rust/Cargo.lock +++ b/tests/test_cases/tests_rust/Cargo.lock @@ -234,7 +234,7 @@ dependencies = [ ] [[package]] -name = "ckb-lua-tests" +name = "ckb-lua-vm-tests" version = "0.1.0" dependencies = [ "blake2b-rs", diff --git a/tests/test_cases/tests_rust/Cargo.toml b/tests/test_cases/tests_rust/Cargo.toml index aef13ac..c246bb0 100644 --- a/tests/test_cases/tests_rust/Cargo.toml +++ b/tests/test_cases/tests_rust/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "ckb-lua-tests" +name = "ckb-lua-vm-tests" version = "0.1.0" authors = ["Nervos Core Dev "] edition = "2021" diff --git a/tests/test_cases/tests_rust/src/tests/lib_ckb_lua.rs b/tests/test_cases/tests_rust/src/tests/lib_ckb_lua_vm.rs similarity index 91% rename from tests/test_cases/tests_rust/src/tests/lib_ckb_lua.rs rename to tests/test_cases/tests_rust/src/tests/lib_ckb_lua_vm.rs index 6f2c423..607e0cc 100644 --- a/tests/test_cases/tests_rust/src/tests/lib_ckb_lua.rs +++ b/tests/test_cases/tests_rust/src/tests/lib_ckb_lua_vm.rs @@ -31,8 +31,8 @@ fn debug_printer(script: &Byte32, msg: &str) { fn gen_tx(dummy: &mut DummyDataLoader) -> TransactionView { let mut rng = ::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); @@ -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 @@ -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(), ]) @@ -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(); diff --git a/tests/test_cases/tests_rust/src/tests/mod.rs b/tests/test_cases/tests_rust/src/tests/mod.rs index 9e57c65..51c1a94 100644 --- a/tests/test_cases/tests_rust/src/tests/mod.rs +++ b/tests/test_cases/tests_rust/src/tests/mod.rs @@ -1,4 +1,4 @@ -mod lib_ckb_lua; +mod lib_ckb_lua_vm; use ckb_traits::{CellDataProvider, HeaderProvider}; use ckb_types::{