Skip to content

Commit 7045c1d

Browse files
committed
Simplify README
1 parent c474dfc commit 7045c1d

File tree

1 file changed

+5
-101
lines changed

1 file changed

+5
-101
lines changed

README.md

+5-101
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,8 @@
1-
# Lua 5.3 in Rust - HACK-3870
1+
# Lua 5.3 port to Rust
22

3-
# How to get started
3+
This is a port of [Lua] [5.3] to the Rust programming language with goal to provide backward compatibility with the PUC Lua, including the C API layer.
44

5-
* Install rust (needs to be a nightly)
6-
* curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
7-
* rustup default nightly
8-
* `cargo b` to build
9-
* `cargo test` to run the tests
10-
11-
# Working on stuff
12-
13-
* Send Alex (aorlenko/khvzak) your github username to be added to the repo to push branches (so you don't have to work from a fork).
14-
* Please don't push to master unless the tests pass!
15-
* Not everything needs porting. E.g. rust supplies printf already, so you don't need to port this
16-
* Note `cstr!` from `macros.rs`, lua uses C strings (0 byte terminated) rust doesn't, this macro helps with that.
17-
* You can replace byte terminated strings with this macro in vscode using the following find and replace regex: `b"(.*)\\0" as \*const u8 as \*const c_char` and `cstr!("$1")`
18-
19-
# Project tracking
20-
21-
https://docs.google.com/document/d/1NmWf19Xf47-Y99b6yKMzoyr2vY6hWXaxNHi1I4nL_vA/
22-
23-
24-
# Examples
25-
26-
## Tests
27-
28-
https://www.lua.org/tests/
29-
30-
Start at `tests/tests.rs`
31-
32-
This sets up a lua environment and then runs the lua 5.3 tests.
33-
34-
# C to rust transpiler
35-
36-
https://github.com/immunant/c2rust
37-
38-
See `onelua.rs` - lua C code transpiled, could be helpful, but kinda hell code
39-
40-
Lots of C preprocessor + macros
41-
42-
Does not include the lua standard libraries at the moment
43-
44-
## How to port files
45-
46-
See `build/` and specifically `build/build.rs` - this includes the mapping of all C files built and what rust code to link them with.
47-
48-
Once things are ported, the `.c` files can be removed (but the `.h` files cannot). Any `.c` code in `build/` is still to be moved and should be deleted once moved.
49-
50-
## Using rust code from C
51-
52-
Search for anything with `[no_mangle]`.
53-
54-
E.g. from lstate.rs
55-
56-
/*
57-
** set GCdebt to a new value keeping the value (totalbytes + GCdebt)
58-
** invariant (and avoiding underflows in 'totalbytes')
59-
*/
60-
#[no_mangle]
61-
pub unsafe extern "C" fn luaE_setdebt(g: *mut global_State, debt: l_mem) {
62-
let tb = gettotalbytes(g);
63-
debug_assert!(tb > 0);
64-
(*g).totalbytes = tb as isize - debt;
65-
(*g).GCdebt = debt;
66-
}
67-
68-
## Using C code from rust
69-
70-
Lua C API https://www.lua.org/pil/24.html
71-
72-
See in lgc.rs
73-
74-
extern "C" {
75-
pub fn luaC_upvalbarrier_(L: *mut lua_State, uv: *mut UpVal);
76-
pub fn luaC_barrierback_(L: *mut lua_State, t: *mut Table);
77-
pub fn luaC_fix(L: *mut lua_State, o: *mut GCObject);
78-
pub fn luaC_newobj(L: *mut lua_State, tt: c_int, sz: size_t) -> *mut GCObject;
79-
pub fn luaC_step(L: *mut lua_State);
80-
pub fn luaC_freeallobjects(L: *mut lua_State);
81-
pub fn luaC_fullgc(L: *mut lua_State, isemergency: c_int);
82-
pub fn luaC_barrier_(L: *mut lua_State, o: *mut GCObject, v: *mut GCObject);
83-
}
84-
85-
## Refactoring
86-
87-
Take some of the ready made `.rs` rust code and make more idiomatic.
88-
89-
* Remove raw pointers
90-
* Use methods
91-
* Stop calculating hashes and use rust native
92-
* Use primitives like vectors
93-
* Remove libc
94-
95-
## Exceptions
96-
97-
Lua uses exceptions a lot (both in lua + in the C api). C by it's nature doesn't have exceptions, so the C api uses `setjmp` and `longjmp`.
98-
99-
Replace with Rust native implementation of exceptions.
100-
101-
## Wrapping
102-
103-
Lua uses integer number overflow and wraparound explcitily. In rust this will cause an exception.
5+
Currently the project is in progress and cannot be used.
1046

7+
[Lua]: https://www.lua.org
8+
[5.3]: https://www.lua.org/manual/5.3/manual.html

0 commit comments

Comments
 (0)