Comments (6)
The following code should work
payload = {
a_key = array({ 1, 2, 3 })
}
from goluago.
Closing this as a solution was found.
from goluago.
This happens because we rely on an "array" marker to efficiently identify the table as an array:
Lines 56 to 58 in 9f09792
from goluago.
Thanks Joey, that works.
@fbogsany It looks like this Lua function can detect arrays in O(1)
, without needing to remember to tag them with a marker:
function is_array(tbl)
return type(tbl) == 'table' and (#tbl > 0 or next(tbl) == nil)
end
This could be converted to go and be used by the JSON utilities. I'm curious how the performance compares.
The array
function call works, but it's not very discoverable.
from goluago.
@amomchilov unfortunately, that isn't O(1)
. The length operator (#tbl
in your example) is O(log n)
where n
is the largest natural key in the table: https://www.lua.org/manual/5.4/manual.html#3.4.7
from goluago.
Interesting!
Do you think that might be prohibitively expensive, though I'm not sure.
I wonder if there are anyways to increase the discoverability of the array
function.
from goluago.
Related Issues (13)
- Enable CircleCI HOT 2
- Push arbitrary Go types on Lua stack
- Write examples for each package.
- Write package docs.
- Write docs for exported funcs and types.
- Automate code-coverage generation.
- Improve code-coverage.
- attempt to index trim 'local' (a nil value) HOT 1
- interface conversion error when trying to `PullTable` HOT 3
- `json.marshal` converts floats to ints
- Create capability of an in-memory zip from a file HOT 3
- Add support for requiring goluago modules with . syntax in lua runtime HOT 1
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 goluago.