kyren
8e3a9f0e84
Add ToString metamethod, make LuaError implement LuaUserData
...
LuaError implementing LuaUserData makes it easy to return LuaResult from a
callback to implement callback functions that can error.
2017-06-23 15:24:03 -04:00
kyren
3ab3970c01
ACTUALLY correctly limit numeric conversions
...
Don't mistakenly do rust-side conversions from integer <-> number
2017-06-23 00:51:16 -04:00
kyren
918edad1b2
Merge pull request #13 from jonas-schievink/example
...
Add a few examples
2017-06-22 14:09:36 -05:00
Jonas Schievink
979e1d1675
Add example to `LuaString::to_str`
2017-06-22 10:49:18 +02:00
kyren
9dc0a3e098
Simplify load / exec / eval
...
load is the fundamental operation here
2017-06-21 19:40:18 -05:00
Jonas Schievink
f75385305c
Add an example to `LuaFunction::bind`
2017-06-22 00:38:08 +02:00
Jonas Schievink
2e87556a1b
Add example to `LuaThread::resume`
...
Adapted from #8
2017-06-22 00:28:44 +02:00
Jonas Schievink
14c168f118
Add `Lua::load` for precompiling chunks
...
This allows loading scripts into memory, performing a syntax check and
precompiling them, without immediately running them like `exec` and
`eval` do.
2017-06-22 00:16:30 +02:00
kyren
06cd2c8e68
Add numeric conversion test
2017-06-21 16:53:52 -05:00
kyren
f0c2f9a870
Method renames, remove ToLua / FromLua impls for Sets
...
There is no single obvious form for a set in lua, and it is not very difficult
to accept a table and convert the sequence values into a set.
Also rename some methods as per discussion.
2017-06-20 18:04:25 -05:00
kyren
7924a910e1
typo fixes
2017-06-19 02:08:50 -05:00
kyren
a0e83b3d1b
Big API change for tables
...
Removes the callback versions of loops over LuaTable, instead now there are
'pairs' and 'ipairs' iterators over them.
2017-06-19 02:04:00 -05:00
kyren
f1dee39416
update reference to raw_length method
2017-06-18 17:11:55 -05:00
Jonas Schievink
16ae4720d6
Rename `LuaString::get` to `to_str`
...
This is what similar types in libstd do (`CStr::to_str`,
`OsStr::to_str`, `Path::to_str`).
2017-06-18 14:48:45 +02:00
Jonas Schievink
a47a6e32ef
Rename `LuaTable::has` to `contains_key`
...
This is what all Rust maps use
2017-06-18 14:39:18 +02:00
Jonas Schievink
ed210e88b5
Rename `LuaTable::(raw_)length` to `(raw_)len`
...
All Rust containers use `len` for this. Even in the Lua API, this is
called `lua_len` and `lua_rawlen`.
2017-06-18 14:36:30 +02:00
Jonas Schievink
de0f3dc3c0
Rename `Lua::load` to `Lua::exec`
...
When talking about "loading" Lua code, it usually means compiling a
chunk of code into a runnable Lua function, but without actually
running it. This makes that clear.
2017-06-18 14:31:38 +02:00
kyren
ba9f7a2ee7
Add mostly untested missing metamethods, improve documentation about them
2017-06-18 00:28:55 -04:00
kyren
56a30fba2e
Slightly more palatable coroutine API
2017-06-17 23:50:40 -04:00
kyren
4d34ccdba1
Merge pull request #9 from jonas-schievink/docs
...
Documentation
2017-06-17 23:28:13 -04:00
kyren
edc5fc8ce3
ACTUALLY check the status of lua threads before calling resume
2017-06-17 22:40:09 -04:00
Jonas Schievink
0e14d787b7
Documentation
2017-06-18 03:31:20 +02:00
kyren
32c83d77b7
small warning / clippy fixes, doc comments
2017-06-15 16:27:39 -04:00
kyren
484479477b
Merge pull request #4 from jonas-schievink/result-to-lua-dejavu
...
Allow passing `Result<T, E>` to Lua
2017-06-15 15:59:20 -04:00
kyren
0d652a3c94
Merge pull request #5 from jonas-schievink/who-needs-macros
...
Remove src/macros.rs
2017-06-15 15:55:54 -04:00
kyren
fc9164ab9f
Merge pull request #6 from jonas-schievink/cfg_attr
...
Utilize `cfg_attr` instead of duplicating code
2017-06-15 15:55:06 -04:00
kyren
0022057058
rustfmt changes
2017-06-15 10:26:39 -04:00
Jonas Schievink
6b651820b6
Utilize `cfg_attr` instead of duplicating code
2017-06-14 01:30:33 +02:00
Jonas Schievink
5019396bd7
Remove src/macros.rs
...
It's not used by anything. It's not even included via `mod macros;`.
2017-06-14 01:24:38 +02:00
Jonas Schievink
80be9e8091
Allow passing `Result<T, E>` to Lua
...
For this to work, both `T` and `E` need to implement `ToLua`. An `Ok(t)`
passes the contained `T`, while an `Err(e)` passes `nil` followed by the
contained `E`. This matches the common Lua idiom used by functions like
`io.open`.
Closes #3
2017-06-14 01:17:41 +02:00
kyren
8440298e71
Go ahead and release 0.5.0
...
partially for the selfish reason that my submodule setup does not deal well with
ureleased versions of cargo libs where the version number ends with -pre
2017-06-11 01:33:08 -04:00
kyren
5c8aa19b8d
Two major API changes:
...
Allow load to return values, allows reimplementing require() like functions
properly.
Make globals table explicit in Lua, remove Lua::get / Lua::set in favor of
Lua::globals. Allows obeying globals metatable, using other Table functions on
the globals table.
Also added "has" method as shorthand for checking whether a table entry is not
nil.
2017-06-11 01:12:25 -04:00
kyren
8203414b76
Use LUA_RIDX_MAINTHREAD instead of weird bespoke method
2017-06-05 05:03:18 -04:00
kyren
7436e84e93
make sure other table methods do not trigger metamethods and errors
2017-06-05 04:10:54 -04:00
kyren
cb7c55f742
Don't need pub on internal function
2017-06-05 01:51:48 -04:00
kyren
1c0b1014ee
Improve performance of create_table / create_array_table
2017-06-05 01:46:45 -04:00
kyren
9aed99e3e3
atpanic function was not a good idea, it's not sound
...
It crosses the C api boundary, the only proper way to panic would be to actually
error guard everywhere, aborting is fine.
2017-06-05 01:05:41 -04:00
kyren
b3218137e1
Somewhat smarter strategy for error_guard calls, less ungodly slow.
...
Also add raw_length table function
2017-06-05 00:41:48 -04:00
kyren
47d4ea62ff
Handle unprotected lua errors SOMEWHAT more elegantly
...
There should be drastically less ways to cause unprotected lua errors now, as
the LuaTable functions which were trivial to cause unprotected errors are now
protected. Unfortunately, they are protected in a pretty slow, terrible way
right now, but it at least works.
Also, set the atpanic function in lua to call a proper rust panic instead.
2017-06-05 00:03:39 -04:00
kyren
e265633fb3
Callback versions of table functions
2017-05-26 23:49:12 -04:00
kyren
53b001cfce
doc update again to test submodules
2017-05-25 12:12:12 -04:00
kyren
c88762e90f
Small doc update (secretly this is just to test submodules)
2017-05-25 12:01:12 -04:00
kyren
acd0611692
Make Lua::to / Lua::from operate the correct way around
...
I know that Lua::to uses FromLua and Lua::from uses ToLua, but it only
makes sense that Lua::from(42) would return the LuaValue for 42, and
that Lua::to::<i64>(v) would convert the given lua value TO an integer.
The way it was just incredibly backwards.
2017-05-25 00:47:48 -04:00
kyren
87a395206d
Correct checking of LuaRef origin, support lightuserdata
...
All lua types should now be at least somewhat usable from rust, if
incompletely so. Any lua value should be readable in Rust as a
LuaValue, pop_value should never panic except in internal logic errors.
2017-05-25 00:43:35 -04:00
kyren
0111625d17
Basic coroutine support, currently very slightly broken
...
There is no longer any protection in passing LuaValue between
independent states, it is being re-added
2017-05-24 23:29:57 -04:00
kyren
5c0f183a52
Improved error handling and formatting
...
Now prints lua backtraces on callback errors as well. This could be
controlled with LUA_BACKTRACE or just RUST_BACKTRACE or similar.
2017-05-22 14:25:36 -04:00
kyren
b15ee9053e
Update to use hlist_macro for hlist macros.
...
You will type hlist! hlist_pat! and HList! so often that every character
counts. Apologize for the API churn in the README.
2017-05-22 11:16:34 -04:00
kyren
edb86bdeb7
Doc updates, remove unused functions
2017-05-21 22:32:16 -04:00
kyren
065c69894a
Initial import
2017-05-21 19:50:59 -04:00