Comments (4)
I'm not sure that this is a good idea to add a new feature flag for a customised Lua, because of the complexity to manage them. Even now with 5 Lua versions supported (5.1, 5.2, 5.3, 5.4, jit) it's quite hard.
If Coco extension is really useful I might consider adding it to the vendored lua-5.1.5
. Given that true coroutines are already supported by luajit
maybe makes sense to add and test new functionality first, under #[cfg(all(feature = "luajit", feature = "vendored))]
? And then consider extending it to the vendored lua-5.1
.
from mlua.
I'm not sure that this is a good idea to add a new feature flag for a customised Lua, because of the complexity to manage them. Even now with 5 Lua versions supported (5.1, 5.2, 5.3, 5.4, jit) it's quite hard.
Currently, there is already a pull request open which adds the flag and alters (hopefully) all the code needed to be compatible with it. All that's left is to add Coco-specific functionality, which I might do as well. Keep in mind that since your enum is not #[non_exhaustive]
, adding a constant is a breaking change. I can't speak for the complexity of keeping this compatibility in the future, but adding basic support should be a couple clicks.
If Coco extension is really useful I might consider adding it to the vendored
lua-5.1.5
. Given that true coroutines are already supported byluajit
maybe makes sense to add and test new functionality first, under#[cfg(all(feature = "luajit", feature = "vendored))]
? And then consider extending it to the vendoredlua-5.1
.
It doesn't make sense for regular Lua 5.1 to suddenly gain Coco when it didn't have it before and none of the other "vanilla" versions have it. Adding a new version is the best way to introduce this functionality without surprising existing code. Coco is a popular and useful patch but it is not so ubiquitous that it deserves to be included unconditionally in the vanilla 5.1 distribution. Additionally including a specific version for Coco allows people to bring their own version and enable Coco-specific functionality once it is added.
As for Coco-specific functionality, there are only a few things that need to be done. Coco only adds a couple new pieces of functionality to the API.
from mlua.
Just tried to play with the coco extension using plain C and mlua with a new function try_yield()
.
My dirty patch to mlua uses local lua-src-rs
crate with modifiedlua-5.1.5
sources for simplicity.
First attempt to test new functionality wasn't successful:
$ cargo test --test thread coroutine_yield --features lua51,vendored -- --nocapture
process didn't exit successfully: `.../mlua/target/debug/deps/thread-af2f8cb09bb556c2 coroutine_yield --nocapture` (signal: 11, SIGSEGV: invalid memory reference)
It failed on MacOS 10.15.7.
Nevertheless, I tested it using C and it also failed with Segmentation fault: 11
:
#include <lua.h>
#include <lauxlib.h>
#include <lcoco.h>
#include <stdio.h>
int thread_fn(lua_State *L) {
printf("before yield\n");
lua_yield(L, 0);
printf("after yield\n");
return 0;
}
int main(int argc, char* argv[]) {
lua_State *state = luaL_newstate();
lua_State *thread = lua_newcthread(state, 8192);
lua_pushcfunction(thread, thread_fn);
lua_resume(thread, 0);
printf("in yield\n");
lua_resume(thread, 0);
lua_close(state);
return 0;
}
However, both examples works on linux.
I don't have much time to debug the extension but apparently it's deprecated and/or contain bugs. It also has removed from LuaJIT 2.1 (no lua_newcthread
function) and the alternative way via coroutine.create()
which I used, as expected, returns attempt to yield across C-call boundary
error.
from mlua.
Just tried to play with the coco extension using plain C and mlua with a new function
try_yield()
.
My dirty patch to mlua uses locallua-src-rs
crate with modifiedlua-5.1.5
sources for simplicity.
First attempt to test new functionality wasn't successful:$ cargo test --test thread coroutine_yield --features lua51,vendored -- --nocapture process didn't exit successfully: `.../mlua/target/debug/deps/thread-af2f8cb09bb556c2 coroutine_yield --nocapture` (signal: 11, SIGSEGV: invalid memory reference)
It failed on MacOS 10.15.7.
Nevertheless, I tested it using C and it also failed with
Segmentation fault: 11
:#include <lua.h> #include <lauxlib.h> #include <lcoco.h> #include <stdio.h> int thread_fn(lua_State *L) { printf("before yield\n"); lua_yield(L, 0); printf("after yield\n"); return 0; } int main(int argc, char* argv[]) { lua_State *state = luaL_newstate(); lua_State *thread = lua_newcthread(state, 8192); lua_pushcfunction(thread, thread_fn); lua_resume(thread, 0); printf("in yield\n"); lua_resume(thread, 0); lua_close(state); return 0; }
However, both examples works on linux.
I don't have much time to debug the extension but apparently it's deprecated and/or contain bugs. It also has removed from LuaJIT 2.1 (no
lua_newcthread
function) and the alternative way viacoroutine.create()
which I used, as expected, returnsattempt to yield across C-call boundary
error.
That's... confusing, and concerning. I understand that Coco is a pretty major hack, but I didn't expect it to break just because you were running Catalina.
Well, if it doesn't work on the latest version of macOS, I suppose it's not acceptable into a Rust crate such as this one. I know it's really not your job to find out why a third-party, unsupported patch set isn't working, so I'll just go ahead and close this. Apologies if I wasted your time.
from mlua.
Related Issues (20)
- Ability to create Luau buffer from bytes / get bytes contents HOT 4
- Hello, is it possible for mlua to write a dll module for standard lua5.3 or lua5.4. HOT 2
- Soundness bug in mlua_sys's luau_compile HOT 2
- Lua::compile is not idiomatic HOT 7
- Lack of Floored Division Support for Luau HOT 2
- Serializing from `serde_json::Value` to `mlua::Value` when the `arbitrary_precision` feature is enabled HOT 2
- `AnyUserData::is` panics with unreachable code after being destructed with `AnyUserData::take` HOT 1
- Automatically generate definition files HOT 4
- Can't re export lua_module in own lib
- Can module mode works with async? HOT 2
- Difficulty creating a wrapper type HOT 1
- Support Audio manipulation HOT 2
- Support UI HOT 2
- Error compiling module to wasm32-unknown-emscripten
- Terra integration?
- Lifetime Issues with Scope HOT 3
- In a module best way to deal with async HOT 4
- Serialization: Recursive table detection yields false positives HOT 1
- Allow setting luau compiler options when loading with `require` HOT 2
- Builds fail with useless errors if user's global Cargo target-dir is changed HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mlua.