1837 Commits

Author SHA1 Message Date
kyren 802d5467c1 Change LuaError ToLua approach
Lua should be consistent independent of the way they are produced.  pcall in lua
should produce the same sort of error that would be returned by a LuaError
conversion.

The situation is not currently great, because LuaError is not Clone, so passing
a LuaError back into rust will result in the error being "consumed".
2017-06-23 19:41:08 -04:00
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 7b7f7f36fc Bump cargo version, bugfix for numeric conversions.
This could arguably be a semver update, but the previous behavior was definitely
not intentional, it was a bug.
2017-06-23 03:28:43 -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
kyren efd77fb862 Merge pull request #12 from jonas-schievink/load
Add `Lua::load` for precompiling chunks
2017-06-21 19:23:22 -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 f92e21d5cb Bump cargo version to 0.6.0 2017-06-20 18:13:40 -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
kyren 5b148536d6 Merge pull request #10 from jonas-schievink/api-revamp
Rename a few methods to better match their intention or conventions
2017-06-18 17:02:18 -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 64d1eae55c New 0.5.x cargo update with important coroutine bugfix, build changes 2017-06-17 23:23:17 -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 7b00ff02f2 enable more lua platform defines in build.rs 2017-06-17 16:56:36 -04:00
kyren 75b7024a93 Merge pull request #7 from jonas-schievink/popen
Enable `io.popen` on Linux
2017-06-17 16:31:09 -04:00
Jonas Schievink 4a980de0ed Allow multiline input in the REPL example 2017-06-17 14:43:05 +02:00
Jonas Schievink 2cddfecfb2 Enable io.popen on Linux 2017-06-17 01:53:51 +02:00
Jonas Schievink 4f05516783 Add a simple repl example 2017-06-17 01:19:21 +02:00
kyren b02dda3431 that example hardly shows ALL the features 2017-06-15 16:30:16 -04:00
kyren 44370dd64e bump cargo version, nice addition of Result conversion 2017-06-15 16:28:12 -04: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