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

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.

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