blackjack
blackjack copied to clipboard
Ability to have an existing file as an input
I've been experimenting with this software for a few days and so far I've been loving it.
I ventured into how nodes are made in Lua and been wondering if there is a way to use an existing file as an input. So far I found out that "file" type is for now only meant for saving files since it opens "save" system dialog via rfd::FileDialog::new().save_file()
.
An ability to change a "mode" of file inputs to "save" or "open" would help me a lot because I would like to make a custom node which reads a pre-generated list of 2D positions from a file.
I've been experimenting with this software for a few days and so far I've been loving it.
Thanks!! :smile: I'd love to see what people are doing with Blackjack, so far the discussion forum has been quiet. Please feel free to share your progress / ideas / frustrations on the discussion forums, it'd help a lot! :heart:
been wondering if there is a way to use an existing file as an input
Not currently, but it's also not a very difficult thing to add. Here's what we would need:
- [ ] The
file
node parameter type needs to take an additional parameter specifying whether it's a file "read" or "write", then we can change therfd
call to use open_file or save_file accordingly. - [ ] Some functions for file IO would need to be exposed to the Lua API. Blackjack is currently using Luau, which is more sandboxed than vanilla lua and functions like
io.open
are not available. Instead, blackjack needs to provide implementations using Rust'sstd
APIs.
After this, users should be able to define their own nodes that can read existing files as strings and do their own parsing. On top of that, we can provide additional functions to parse common file formats. I already have a function to load an OBJ file into a mesh somewhere in the codebase, so it would only need to get exposed to the Lua API.
Let me see if I can tackle this :thinking:
Alright, that was faster than I expected :smile: All the required bits are there, but the code still lives on my development branch. You can find the changes in 86c89d5dcbb0, or feature/lua_api_proc_macro
. Things should work if you stay on that specific commit, but I make no promises about the branch itself.
In case you do that, there's a couple of things to keep in mind:
- You can now use
Io.read_to_string(path)
andIo.write(path, contents)
inside Lua code. These are equivalent tostd::fs::read_to_string
andstd::fs::write
from Rust. These should work on any custom node. I've added anode_params.lua
file creating a custom node that reads some data. - You can now use
require
inside lua code. To define new nodes, it is now recommended to uselocal P = require("params")
at the top of your file, and define any inputs and outputs using that module, so where you usedv3
, you can now useP.v3("some_vector", vector(1,2,3))
. After this, you can get rid of all the ad-hoc definitions at the top of the file. You can find documented versions of these functions inblackjack_engine/src/lua_engine/node_params.lua
. - User code does no longer live inside the
node_libraries
folder. It is now insideblackjack_lua/run
. Anything you put onblackjack_lua/lib
will be available to require, soblackjack_lua/lib/foo.lua
can be required asrequire('foo')
.
This is part of a bunch of upcoming features, together with better ergonomics to expose lua functions and documentation powered by ldoc.
This was merged a couple days ago as part of #45. There is a Import OBJ node that should serve as example for custom code.