Comments (3)
You can read values from a table reference using luerl_emul:get_table_keys/3
, but only if you know the key you want to access.
Lua0 = luerl:init(),
{TableRef, Lua1} = luerl:get_table1([<<"math">>], Lua0),
{Value, Lua2} = luerl_emul:get_table_keys(TableRef, [<<"pi">>], Lua1).
Getting the entire table is more difficult because tables are split into the 'array part' and the 'dictionary part'.
Getting only the keys from the 'dictionary part' could look something like this if defined in luerl_emul
:
get_table_key_list(#tref{i=N}, #luerl{ttab=Ts}=St) ->
#table{d=Dict} = ?GET_TABLE(N, Ts),
Keys = ttdict:fetch_keys(Dict),
{Keys, St}.
from luerl.
Awesome thanks. Updated the wiki page. I thought get_table_keys
would give me a list of table keys :).
from luerl.
The functions luerl:get_table/2
and luerl:get_table1/2
are just wrappers around luerl_emul:get_table_keys/2/3
where the first one encodes the list of keys into internal format. You don't have to explicitly find the first table.
The reason tables are split into 2 parts is make the array use of them with integer keys faster. A simple test I did gave about 20%. I will check out whether using maps is faster than the array module. Unfortunately I can't use maps for the whole table as their is no support for doing next
efficiently.
from luerl.
Related Issues (20)
- luerl.do returns raw table reference instead of decoded value HOT 3
- Persistent data structures HOT 15
- os.time and os.date API incorrectly implemented HOT 5
- 5.3 converting hex string to decimal error
- The collectgarbage() function is for now a no-op HOT 2
- Release request: 5.3 beta version HOT 3
- Loading third-party library redis failed HOT 3
- Whether to support multi-lua script file parsing HOT 3
- What the 'Reductions' meaning in sandbox? HOT 2
- ability to run lua program line-by-line / pause execution and return to caller HOT 4
- failed to add "require" to the lua script
- string.format crash and inconsistency HOT 4
- Update luerl in hex.pm HOT 4
- more documentation for Mod:install in load_module
- pcall and division by zero HOT 6
- Executing a Lua function from within Elixir does not return the mutated state HOT 5
- Garbage collector removes environment for functions stored in a table in _G HOT 3
- store/retrieve luerl_state
- string.gmatch HOT 1
- load function regression failure in 1.0 HOT 2
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 luerl.