Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

Embedded scripting languages

Name: Anonymous 2014-11-06 8:40

What scripting language would you embed to a program? The performance would not be main issue, since the compiled part of the program would worry about that.

The scripting language would call many functions written in C, C++, or whatever lang that can compile C-like functions (so there needs to be some kind of easy to use FFI).

I thought about options here:
- Lua
- Scheme (tinyscheme or whatever)
- Something else?

Now, what would /prog/ use, and why? ("Read SICP" is not a valid answer here)

Name: Anonymous 2014-11-06 9:51

Make your own based on sexpressions or use a pre-made scheme implementation.
Or just... use C.

Name: Huskellfaggot 2014-11-06 11:37

I'm currently using haskell as my scripting language. It /can/ call C++, but its a bit of a pain. You have to write the bindings yourself, most of the time.

Name: Anonymous 2014-11-06 19:08

You should first ask yourself if you really need an embedded scripting language. If you don't need to expose scripting functionality to end users, then you'll probably be better served by keeping everything in C or C++ and at most using a higher level language for compile-time data generation. And think hard about that, because a lot of the reasons people give for including scripting support (like data entry) can be trivially solved without a complete programming language.

Name: Anonymous 2014-11-06 19:12

>>4
and I should add that in my experience, the complexity of marshaling data between the main application and the scripting language, scheduling garbage collection, and whatnot usually outweighs the concision gained by writing part of the program in a higher level language, so it's really not going to be a win unless you write most of the program in the scripting language, or you truly need scripting to extend i.e. your editor.

Name: Anonymous 2014-11-06 19:13

Lua is utter fucking shit, don't use it under any circumstances.

Name: Anonymous 2014-11-06 19:18

Javascript via v8.

Name: Anonymous 2014-11-06 22:49

>>7
kill yourself

Name: Anonymous 2014-11-07 0:13

>>6
What's wrong with Lua? Serious question, I'm not really familiar with it.

Name: Anonymous 2014-11-07 0:23

Talking about "embedding"...

http://www.youtube.com/watch?v=5GJGDw1mEjc

Name: Anonymous 2014-11-07 0:24

Name: Anonymous 2014-11-07 1:03

>>11
You're a fucking retard.
1. That presentation is from 4 years ago, and it's about a fucking Xbox 360, hardware from almost a decade ago
2. It's profiling Lua, not Luajit, which is able to eliminate most of those indirections for constant key lookups nowadays.
3. If you really need the performance, luajit's FFI lets you use C structs with the expected semantics and performance.
4. Lua's syntax is fine.

The only real problems I have with luajit are that arrays start from 1, that the standard library is practically nonexistent, and that it's not a lisp.

Name: Anonymous 2014-11-07 1:06

4. Lua's syntax is fine.
Hah!

Name: Anonymous 2014-11-07 1:24

>>13
It's just Algol with keywords instead of brackets. If you're a lisper that's cool, but you really have nothing to complain about if you prefer Python or whatever.

Name: Anonymous 2014-11-07 1:29

>>1-15
Read SICP.

Name: Anonymous 2014-11-07 1:40

>>14
Assignments are not expressions in lua. This automatically makes lua trash compared to most ALGOL-based languages.

Name: Anonymous 2014-11-07 1:42

>>16
You have very low standards for programming languages.

Name: Anonymous 2014-11-07 1:49

>>17
This is only one of the reasons that make lua trash, so no.

Name: Anonymous 2014-11-07 3:48

>>18
Tell me the other reasons then.

Name: Anonymous 2014-11-07 12:39

>>16
Assignments being expressions are only handy in languages that are terribly shitty to begin with, e. g C and C++
In a real imperative language statements and expressions are separate, because you do not need crutches like assignment being an expression to check errors and exit loops.

Name: Anonymous 2014-11-07 12:41

>>19
Let's ask Nikita
While web-development is plagued by PHP/Perl/JS/Ruby/Python scourge, video game development too has its share of bad languages. Most hyped and infamous of them being Lua:
- Broken lexical scoping: assignment acts as declaration, clobbering global variables. Even worser: access to undeclared variable doesn't produce error, but silently returns nil. Bad scoping is the single biggest source of bugs and confusion (http://lua-users.org/lists/lua-l/2008-11/msg00008.html). Moreover, every variable access goes through hashtable system, producing several L2 cache misses in process, making Lua slower than comparable alternatives, like Lisp. Lua has no standard way to do OOP or define a module, leading to numerous incompatible and badly designed solutions, resting on top of already deficient hash-table system with a.b[i]:c(d) style scope resolution. Like in all badly designed languages, Lua pollutes global scope with `_` prefixed identifiers, instead of keeping them in a separate package.
- Hash-Table as a primary data structure has overwhelming issues. There is no simple and safe way to implement Lisp-like FIRST and REST functions: either you have to copy whole Table or modify it, and sequential access is somewhat slow. There is no easy way to remove an element from a list. Even worse, the size of a list may not be what you expect: "b={'x'};b[2]='y';print(#b)" prints 2, but "b={'x'};b[3]='y';print(#b)" prints 1. Table indexing starts from 1, acting as a source of errors and confusion, when interfacing with external APIs or converting algorithm from Lua to C/C++, while 0 still acts as a dangling pointer. Lua Tables don't provide advantages of immutable catenable queues - a silver bullet data structure, you'll find in modern Lisps and Haskell; Lua Tables are mutable and encourage modification, instead of creation, meaning there is no easy way to do functional programming with Lua. REPL wont pretty-print tables, but dump something like "table: 0x807e978". Table-list features some of the scariest kludges: program can modify the behavior of the length operator for any value but strings through the __len metamethod, while table construction syntax and semantic are impenetrably confusing, like { [f(1)] = g; "x", "y"; x = 1, f(x), [30] = 23; 45 }
- Lua uses floating point values to represent integers, so 9999999999999999999==10000000000000000000. In general, Lua's logic seems odd: "nil+1" produces error, while "(not nil)+1" gives 2. Things could be unequal to itself: `t={[{1,2,3}]="abc"}; print(t[{1,2,3}])` wont print "abc", meaning that `{1,2,3} != {1,2,3}`.
- Lua's syntax is inconsistent and full of quirkiness: underscores for special variables and cryptic symbols for simple functions, like `#xs` for `length(xs)` and `x = start,end,step` instead of range(start,end,step), while logical connectives (`and`, `or` in place of `&&`, `||`) are hard to notice between other symbols, and do/then/end everywhere could be annoying. Moreover, `t = {"a","b","c"}; print(t[2])` works, but `print({"a","b","c"}[2])` fails. `print 'hello';` works, but `print 123;` fails.
- Lua is unstable: API changes frequently, functions are being added and deleted continuously, `table.foreach` being a good example of to be deleted function, and then there is `table.unpack`, which present only in some versions of Lua.
- Lua's GC is a naive mark-and-sweep implementation, which stores the mark bit directly inside objects, a GC cycle will thus result in all objects being written to, making their memory pages `dirty` and Lua's speed proportional to the number of allocated objects. Lua simply was not designed to support hundred thousand objects allocation per second.
- Lua was built as a glue language, and it shows. Much of Lua hype comes from it's usage as a simple integrated scripting language in video games industry. That makes typical Lua user a teenage gamer with little expectations or taste for computation features and productivity.

Name: Anonymous 2014-11-07 13:45

check out my dbus

Name: Anonymous 2014-11-07 15:53

>>8
No you kill yourself. Why would Javashit be a bad scripting language? V8 is already written, just waiting on you to link it in.

Name: Anonymous 2014-11-07 16:41

>>23
Why would Javashit be a bad scripting language?
Because Javashit is crap? Is that even a question?

Name: Anonymous 2014-11-07 18:44

Broken lexical scoping: assignment acts as declaration, clobbering global variables.
Lexical scoping is there with local variables. Yes, global by default is annoying, that's why many use a patch or strict.lua to prevent accidental global variable creation inside of functions.
Moreover, every variable access goes through hashtable system, producing several L2 cache misses in process
Unless you use luajit, in which case it turns typical "object.member" looking lookups into simple constant field accesses.
making Lua slower than comparable alternatives, like Lisp.
What Lisp? Common Lisp? Too fucking big to embed, unless you use something like CLISP which is going to perform worse than luajit or probably even PUC-RIO Lua and isn't acceptible due to its use of the GPL, or ECL which requires the user to have a C compiler installed and thus unacceptable for Lua's use cases (games and scripting languages for data editing and visualization tools)
Scheme? There is no good Scheme that approaches Luajit's performance and ease of embeddability. Stalin is AoT compiled so not useful for this niche and it's abandoned anyway, most of the Schemes are incredibly bloated, the embeddable ones are even more limited than Lua and don't have incremental GCs necessary for stutter-free operation.
Hash-Table as a primary data structure has overwhelming issues. There is no simple and safe way to implement Lisp-like FIRST and REST functions
Stop thinking in a different language, just iterate over the table with a for k,v in pairs(t) loop.
sequential access is somewhat slow
Luajit and even PUC-RIO Lua turn numerically indexed tables into vectors nowadays.
There is no easy way to remove an element from a list.
t.k = nil
Table indexing starts from 1
I'll agree on this one, it still pisses me off.
meaning there is no easy way to do functional programming with Lua.
That's a good thing, THE FORCED GENERATION OF SUPERFLUOUS GARBAGE has no place in a game.
while table construction syntax and semantic are impenetrably confusing, like { [f(1)] = g; "x", "y"; x = 1, f(x), [30] = 23; 45 }
You're mixing the syntax for array tables and hashtables into one construction, of course it's going to look weird, and of course no one ever does this in practice.
Lua uses floating point values to represent integers, so 9999999999999999999==10000000000000000000
If you really need to represent an integer larger than 2^52, luajit's FFI supports 64 bit integers.
Things could be unequal to itself: `t={[{1,2,3}]="abc"}; print(t[{1,2,3}])` wont print "abc", meaning that `{1,2,3} != {1,2,3}`.
This is equivalent to the = vs. eqv? vs. equal? trichotomy in Lisps. You're comparing their identity, of course they're not the same.
Moreover, `t = {"a","b","c"}; print(t[2])` works, but `print({"a","b","c"}[2])` fails.
Why would this ever matter
`print 'hello';` works, but `print 123;` fails.
That's because Lua allows you to skip the parenthesis for function calls with a string as their only parameter.
Lua is unstable: API changes frequently, functions are being added and deleted continuously,
Oh wow Nikita, Lua is one of the slowest changing languages in common use, and in practice everyone uses 5.1 anyway because that's what Luajit is based off of.
Lua's GC is a naive mark-and-sweep implementation
Not true for Luajit, and even Lua has incremental GC now.
That makes typical Lua user a teenage gamer with little expectations or taste for computation features and productivity.
lol

I'm disappointed in you, Nikita, and disappointed in >>21-san for reposting that. Almost all of those flaws are either complete non-issues or simply not true. If you're going to bitch about Lua, at least bitch about things that actually make a difference like how the standard library is almost as useless as R5RS's.

Name: Anonymous 2014-11-07 20:00

Someone's defending Lua on /prog/. What's next, /prog/ becomes a social network?

Name: Anonymous 2014-11-07 20:19

We need these links after each post:

Follow me on: [ Github ] [ Facebook ] [ Twitter ] [ Tumblr ] [ LinkedIn ]

As for luajit, everywhere I look it says that it still has the cache problem but that may just be outdated.

Name: Anonymous 2014-11-07 21:20

>>26
I've defended Lua on /prog/ for years now. It's not my favorite language but it's a lot better than you guys are making it out to be; in particular, the complaints about performance are downright retarded when LuaJIT wipes the floor with just about every other dynamic language, and provides comparable throughput to average C and C++ (naïve, safe stuff with lots of heap allocations, not VROOM VROOM OPTIMIZED stuff with custom memory allocators and whatnot) when you use LuaJIT's FFI types.

If you want to ship an application with an embedded scripting language on Windows, Linux, and OSX, LuaJIT is the best choice, hands down. Everything else has some combination of these problems:
-performance isn't as good
-footprint is too large (fuck you, I'm not gonna ship a 100+ megabyte Common Lisp runtime)
-inadequate Windows support (I don't give a fuck about your FSF dogma, I write programs for normal people and normal people use Windows)
-is a toy some kid made for a CS project that doesn't have a large userbase working out the bugs and funding development
-is stuck in web server/command line scripting la-la-land with zero concern for putting bounds on latency (LuaJIT isn't perfect at this either but the incremental GC gives you a lot more control than most languages dynamic languages)
-shit FFI requiring you to waste time with wrappers

I'd rather be using a Lisp, but none of them are even close to being as good as LuaJIT in these aspects.

Name: Anonymous 2014-11-07 22:44

>>28
You can defend it all you want, but without that kind of criticism, LuaJIT might not even exist. That and other criticism is well-deserved. From my point of view:

Performance should never have been an issue. Look at Io--it doesn't have a fancy JIT or a real VM, but it pretty much always had optimizations that put the "we're so legit you have to pay us for docs" Lua to shame. Getting schooled by one of the fly-by-nights you so casually insult.

Metatables are an antipattern, especially in proto-oo where you can usually achieve the same thing with less mess by relying on the language semantics. But like Javascript, Lua hates its proto-oo heritage and doesn't do it justice. Why even bother?

1-based indices are stupid and effectively impossible to fix. What little library support Lua has presumes it.

Assignment is either by ref or by copy, depending on undocumented semantics. I've observed an alarming number of copies. So much for avoiding superfluous garbage.

Embedding Lua isn't as nice as you think. Lua makes a mess of the stack whenever something goes wrong. You can make this work with C, but if you want it to work with anything else you've got a lot of low-level code to write. No wrappers, huh?

The array indexing thing wouldn't be bad if Lua behaved more like a functional or array-based language. There's no good reason for prototypes in Lua as it stands, it does proto-oo a disservice and it does Lua a disservice. Everything sucks hard to embed: Lua, Scheme, Perl, Io, Ruby, Python, Javascript--unless you're embedding it in C, then it's usually manageable. You've still got the vomit bag that is GC and exception interop to worry about.

The only really good thing about Lua is LuaJIT. It's actually good enough to make Lua worth using, since it is small and pretty fast and sometimes that's all you care about. But defending Lua the language? Why?

Name: Anonymous 2014-11-08 2:08

>>29
Using metatable overloads for OO is probably my least favorite thing about Lua. I mean, it's a neat trick, but having to do at least three table lookups just to access a parent member is just insane for a language that's supposed to be lightweight and reasonably fast.

Name: Anonymous 2014-11-08 2:57

>>30
Then copy the methods into the parent table.

Name: Anonymous 2014-11-08 2:58

>>31
*child table

Name: Anonymous 2014-11-08 3:08

>>32
Pedo

Name: Anonymous 2014-11-08 3:36

>>30
Good proto oo languages optimize proto lookups with a cache so it's constant time, and have no need for metatables because they honor Alan Kay's late binding/encapsulation ideals: the object itself determines how it responds to a message. You can change it all without resorting to any special mechanism.

Name: Anonymous 2014-11-08 3:38

>>31-32
That's not a satisfactory solution if you have a lot of children, and it only works for functions, not plain old data.

Name: Anonymous 2014-11-08 10:54

Is there any reason to use regular Lua instead of LuaJIT? They have the same C API, don't they?

The discussion here indicates that the Lua from lua.org is very slow. However, many people claim it's pretty fast and light. Faster than Python, for example. So who is right?

Name: Anonymous 2014-11-08 11:34

You all seem to be missing a point here. Fortran is faster than C in some instances, but its syntax is shit. Sure, Lua(JIT) may be faster than any other scripting language, but it's still a watered-down Javashit clone made by a Brazilian kike.

Name: Anonymous 2014-11-08 21:25

>>36
"Faster than Python" doesn't mean much. Python is slowwer than Perl for fucks sake.

>>37
The problem with Fortran is not really the syntax. People think languages are all syntax, but the semantics are much more important. Fortran isn't a loser there either exactly, but C is better at telling a microprocessor what to do, and good enough at Fortran things to dominate.

Name: Anonymous 2014-11-08 21:35

Embed C scripting into your ATS programs

Name: Anonymous 2014-11-08 21:47

>>25
This is equivalent to the = vs. eqv? vs. equal? trichotomy in Lisps. You're comparing their identity, of course they're not the same.
Only a very shitty language designed by programmers with BS in SD who only know C and unix shell would make != an object address comparison operator instead of value comparison.

Name: Anonymous 2014-11-09 0:09

>>37
A "Javashit clone"? I'm not sure if you actually ever used Lua or Ecmascript before, or just shitposting.

fuck this stupid thread

Name: Anonymous 2014-11-09 8:04

>>38
Actually, being faster than Python means a lot. For instance, Haskell is NOT faster than Python:

http://stackoverflow.com/questions/26765232/haskell-hashtable-performance

Name: Anonymous 2014-11-09 13:09

>>42
And everyone knows Haskell compiler can do more to optimize than C compiler. So Haskell is faster than C. And Lua is faster than Haskell. That means Lua is faster than C. And LuaJIT is event faster than that!

Name: Anonymous 2014-11-09 15:26

>>42
Terrible!

Name: Anonymous 2014-11-09 16:19

>>42
This argument gets posted over and over. It is irrelevant. Nobody uses the hashtable module in Haskell.
Compare stuff that matters: pure Python and pure Haskell text and XML processing, parallel numerical computation, parser performance. Check the goddamn language shootout.

>>44
Terrible[i] dubs.

Name: Anonymous 2014-11-09 17:08

>>45
Since when does the goddamn language shootout have any weight? It's biased by design as it compares unidiomatic, specially contrived programs only. The Haskell there looks like C, damn it. But if you want to write in C, you'll write in C, not in a C-like Haskell, right? The shootout is bullshit.

Compare stuff that matters
Ooh, so we're playing the game called "denial"? Any place where Python beats Haskell with all its static typing and glorious compiler optimizations and Haskell can only match using a wrapper around a C library, is "stuff that doesn't matter"? Haha.

Name: Anonymous 2014-11-09 18:20

>>36
Is there any reason to use regular Lua instead of LuaJIT? They have the same C API, don't they?
LuaJIT supports Lua's C API, but it also has its own FFI that drastically simplifies calling in and out of C (no wrappers, just ffi.cdef "void whatever(void);" and you're off) and allows you to directly use C types with good (JIT compiled) performance.

>>37
Do you really think Javascript is a better programming language than Lua? Don't you have some websites to be apping?

>>40
Are you saying Common Lisp and Scheme are shitty?
Everything but tables and functions compares by value in Lua (strings are interned so that strings with the same contents are only stored once, so a pointer comparison is all that is needed for them). Most of the time, a cheap comparison of pointers for identity of is more useful for complex objects than an expensive deep comparison, so it makes sense to reflect that in the syntax.

Name: Anonymous 2014-11-09 18:33

>>41,47
I never implied Javashit was any better than Lua. Why would I call it Javashit then?

It's a Javashit clone because both are simplistic asspulls with no real thought that use shitty number types, have no real data structures other than half-assed table/dictionaries, have gay syntax and are popular for their ``epic embedding capabilities as a scripting language in rocking web apps''.

My wording must have been wrong. Certainly JS isn't a Lua clone, even thought both share bad features. Calling Lua a JS clone would be like calling C an ALGOL clone, and that sounds indeed retarded. Sorry about that.

Name: Anonymous 2014-11-09 20:48

>>46
I can write a shitty C library that will be outperformed by both python and haskell analogues. So what? Fuck you.

Name: Anonymous 2014-11-09 20:51

>>46
Python outperforms haskell in this particular case because it is comparing C code (CPython to be exact) with pure Haskell:
http://hackage.haskell.org/package/hashmap-1.0.0.2/docs/src/Data-HashMap.html
Oh wait, did you not know that Python is not self-hosting and that the only interpreter you are likely to encounter is written in C and all dict operations are implemented in low-level C with bit-mangling? Holy shit, this must surprise you much!
You may bring up PyPy, which uses platform-specific JIT, but you won't because you're a retard. Fuck off

Name: Anonymous 2014-11-11 3:30

>>46
The authors of the shootout know this very well. That's why they preface their page with this:

Measurement is highly specific -- the time taken for this benchmark task, by this toy program, with this programming language implementation, with these options, on this computer, with these workloads.

Same toy program, same computer, same workload -- but much slower.

Measurement is not prophesy.

Name: Anonymous 2014-11-11 20:41

>>51
Yes, but why do you ignore that and refer to it like it's a representative benchmark suite? Comparison of the fastest among the fastest programs is obviously impractical because 90% of the time when you write in any language, you want to write straightforward and idiomatic programs, not spend a shitload of time optimizing them to reach that language's top speed. And in that 10% of times when all-out optimization is necessary, you'll be better off just using C or C++ or Assembly, so comparing them to a crapload of slower languages is pointless too. So the results of that shootout are pointless in 100% of cases.

Name: Anonymous 2014-11-11 21:04

whatever systemd uses

Name: Anonymous 2014-11-13 19:15

>>53
Well, as of the latest version straight from Lord God Poettering, systemd uses your anus. For pleasure.

Name: Anonymous 2014-11-13 20:32

Name: Anonymous 2014-11-16 17:10

How do you implement an object-oriented programming language without representing the objects as hash tables? For it to be truly OO, you need to be able to add and remove arbitrary object fields during runtime, so the interpreter/runtime/VM needs to use some sort of dynamic representation for them. Or do you just analyze the AST to determine that a certain prototype chain only ever has certain certain fields, and then translate them into memory offsets?

Name: Anonymous 2014-11-16 19:22

>>56
LuaJIT and the various Javascript JITs use runtime information to suss out the "hidden types" common in dynamic language programs. It might look something like this:

1. Our instruments indicate this function is being called a lot. It returns one object, let's see what happens to it.
2. Our instruments indicate that 99.99% of these objects will never have any fields added or removed from them. Looks like a static type.
3. Let's change this function so that it creates a vector with a fixed number of slots, and replace every hash lookup with a direct index into those slots.
4. If a field is added or removed from one of these objects, we back out and convert it into a hash table.
5. If this happens enough times, we should consider recompiling the original function.

IIRC LuaJIT goes a step further, assumes tables will be static by default, and converts any keys visible in the program text into a static lookup from the get go, but you get the idea. Storing everything in hash tables is the simplest, most general way to implement a dynamic language, but you absolutely can optimize it further if you're willing to complicate the implementation and add checks so that the optimization can be reverted if your assumptions turn out to be false.

The downside is increased runtime overhead vs. an ahead of time compiled language. The upside is that a good JIT can take advantage of information that might not be available to a static compiler. i.e. if a function is called thousands of times with one of its inputs never changing, and this input was read from user input and not statically knowable, an AoT compiler would have no choice but to make use of a general function suitable for all inputs, while a JIT could still produce a specialized version of the function for that input. The sweet spot between strictly AoT C and the crazy JITs of Lua and JS would be something like Common Lisp, where the programmer has access to the compiler at runtime and it's their own responsibility to compile specialized versions of functions.

Name: Anonymous 2014-11-16 19:41

>>56
Analyzing the AST only gets you so far because you would have to do it at run time in some cases at least. In a lot of cases it would just take longer to do the analysis.

Interned strings are a good start. As a hash key, they don't need hashing and they will never produce collisions. There is voodoo going on with caching too, which I'm still not clear on.

Name: Anonymous 2014-11-16 19:51

>>57
Splendid, thank you. I was wondering if I'd missed some major interpreter design innovation, but as usual in CS, there's no silver bullet—just a lot of heuristics.

Name: Anonymous 2014-11-16 20:08

>>58
You still need to (mod N) interned strings to fit them in an N-slot hash table, which can absolutely cause collisions, though?

And I don't really get the caching argument against hash tables—if you use open addressing or coalesced hashing, all hash entries are located in a single contiguous block of memory, which should have the exact same hashing characteristics as a vector, unless the wasted space and pseudorandom distribution within it is that significant.

Name: Anonymous 2014-11-16 21:24

>>60
Limiting case: if you intern them you can take the drastic measure of enumerating them and using that for the hash key. At which point, you will need to exceed N different strings to get a collision.

Caching isn't an argument against hash tables. You want to cache things to keep from getting a lookup explosion every time you send a message.

Name: Anonymous 2014-11-23 22:17

>>66
nice dubs mate

Name: Anonymous 2014-11-24 2:16

I like using lua for purely sentimental reasons.

Name: Anonymous 2016-11-16 16:30

>>56
Why can't you just use an array of pointers?

Name: Anonymous 2016-11-16 17:24

>>66
Nice dubs

Name: Anonymous 2016-11-16 17:24

>>65,67
Thank you

Name: Anonymous 2016-11-16 17:25

>>66
Nice dubs

Don't change these.
Name: Email:
Entire Thread Thread List