You are not logged in.
Hope you brought your flamethrowers because I am feeling a bit chilled.
Sooo I am knee deep in some heavy javascript(Nodejs) and while fighting to populate an array with the results of a sqlite query
(somehow my array is getting nuked nodejs or nodejs-sqlite3 bug?
)
I am left scratching my head saying to my self WTF!! This would have taken me like 5 sec in Qt C++. So I wrote up the same example
in Ruby, Python, Java, Lua and Perl. And in every case my Qt C++ example was not only cleaner, shorter but easier to write/understand.
Granted scripting languages are not only valuable but necessary in CERTAIN cases, but the way people use them today is just INSANE.
My primary scripting language is javascript but that is only because my work requires it. But ill take lua over any scripting language any day.
I am going to go sink my teeth in Django see if that pisses me off any less!
Sooo whats your opinion.
Last edited by zester (2011-09-13 05:19:18)
Offline
Good luck with this. ![]()
This thread may be kept running as long as the discussion remains considerably sane.
If it runs out of hands it will surely be closed at once.
Throw in your arguments, folks, but keep away from unnecessary flaming!
To know or not to know ...
... the questions remain forever.
Offline
Good luck with this.
This thread may be kept running as long as the discussion remains considerably sane.
If it runs out of hands it will surely be closed at once.Throw in your arguments, folks, but keep away from unnecessary flaming!
Lol I was waiting for a moderator to swoop in, didn't take you long at all.
Offline
Another moderator swooping by -- You do enjoy a good argument, don't you ![]()
I've watched your other threads, and I must say you tend to stand your ground and are not trollish. Enjoy...
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
The shortest way to ruin a country is to give power to demagogues.— Dionysius of Halicarnassus
---
How to Ask Questions the Smart Way
Offline
Granted scripting languages are not only valuable but necessary in CERTAIN cases, but the way people use them today is just INSANE.
My primary scripting language is javascript but that is only because my work requires it. But ill take lua over any scripting language any day.
Bit of a non argument really as your statement (not a question) is absolutely correct ![]()
Javascript being the most overuse / abused of them all ![]()
Last edited by satanselbow (2011-09-13 06:18:38)
Offline
Another moderator swooping by -- You do enjoy a good argument, don't you
I've watched your other threads, and I must say you tend to stand your ground and are not trollish. Enjoy...
I am a lets sit down and have a nice discussion over a cup of coffee type of guy. I think I got a little hasty in my
javascript frustrations and created this topic.
We need a delete button for general users who create topics. For when they want to back out ![]()
Offline
We need a delete button for general users who create topics. For when they want to back out
No chance!
You have to stay this now.
To know or not to know ...
... the questions remain forever.
Offline
I am left scratching my head saying to my self WTF!!
As a programmer, I know that feeling all too well...
Doesn't matter what language I'm programming in. ![]()
After a while in C++, I really appreciate not having to compile code all the time - be it PHP, jQuery, Lisp, even Javascript.
Quality of code can be measured in WTFs per minute - or so they say. ![]()
Less noise. More signal.
Offline
@zester: Would you mind to show the examples you've written?
Offline
zester wrote:I am left scratching my head saying to my self WTF!!
As a programmer, I know that feeling all too well...
Doesn't matter what language I'm programming in.
After a while in C++, I really appreciate not having to compile code all the time - be it PHP, jQuery, Lisp, even Javascript.Quality of code can be measured in WTFs per minute - or so they say.
I'm never entirely sure whether WTF should be model, view or controller :S
Offline
But ill take lua over any scripting language any day.
But Lua is a scripting language. Maybe I missed the joke?
Offline
But ill take lua over any scripting language any day.
But Lua is a scripting language. Maybe I missed the joke?
I think he could be pointing that of the many scripting languajes he has used, seems that only LUA satisfies him, and it's not widely used as he would like. That's what it seemed to me.
Best Testing Repo Warning: [testing] means it can eat you hamster, catch fire and you should keep it away from children. And I'm serious here, it's not an April 1st joke.
Offline
keenerd wrote:But ill take lua over any scripting language any day.
But Lua is a scripting language. Maybe I missed the joke?
I think he could be pointing that of the many scripting languajes he has used, seems that only LUA satisfies him, and it's not widely used as he would like. That's what it seemed to me.
Well it's part that and part rant. But the topic in general wasn't meant to be taken seriously.
-------------------------------------------------
Programming languages are in the eye of the beholder. There is no
one language that is better than another. Some might be better suited
for a particular situation, But then again that comes down to preference.
Last edited by zester (2011-09-13 17:42:38)
Offline
This would have taken me like 5 sec in Qt C++. So I wrote up the same example
in Ruby, Python, Java, Lua and Perl. And in every case my Qt C++ example was not only cleaner, shorter but easier to write/understand.
on the face of it, your comparison seems completely bogus. qt isn't a language; it's an application framework.
try re-writing your examples using the relevant bindings for qt.
Offline
keenerd wrote:But ill take lua over any scripting language any day.
But Lua is a scripting language. Maybe I missed the joke?
I think he could be pointing that of the many scripting languajes he has used, seems that only LUA satisfies him, and it's not widely used as he would like. That's what it seemed to me.
Somewhat ironically (within this threads context) - one of Lua's biggest selling points is it's simple integration with other languages, both scripting and higher level.
Offline
ethail wrote:keenerd wrote:But Lua is a scripting language. Maybe I missed the joke?
I think he could be pointing that of the many scripting languajes he has used, seems that only LUA satisfies him, and it's not widely used as he would like. That's what it seemed to me.
Somewhat ironically (within this threads context) - one of Lua's biggest selling points is it's simple integration with other languages, both scripting and higher level.
Good point!
Lua is insanely <-- Word of the day (Pee-Wee Herman Play House AHHHHHHHHHH) easy
to embed and bind.
Little examples I wrote a couple of years ago sooooo it is what it is.
If using C++
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
How to call a C Function from Lua
luaavg.c
#include <stdio.h>
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
/* gcc -o luaavg luaavg.c -I/usr/local/include -L/usr/local/lib -llua -lm -ldl */
/* the Lua interpreter */
lua_State* L;
static int average(lua_State *L)
{
/* get number of arguments */
int n = lua_gettop(L);
double sum = 0;
int i;
/* loop through each argument */
for (i = 1; i <= n; i++)
{
/* total the arguments */
sum += lua_tonumber(L, i);
}
/* push the average */
lua_pushnumber(L, sum / n);
/* push the sum */
lua_pushnumber(L, sum);
/* return the number of results */
return 2;
}
int main ( int argc, char *argv[] )
{
/* initialize Lua */
L = lua_open();
/* load Lua base libraries */
luaL_openlibs(L);
/* register our function */
lua_register(L, "average", average);
/* run the script */
luaL_dofile(L, "avg.lua");
/* cleanup Lua */
lua_close(L);
/* print */
printf( "Press enter to exit..." );
getchar();
return 0;
}
-- call a C function
avg, sum = average(10, 20, 30, 40, 50)
print("The average is ", avg)
print("The sum is ", sum)
avg, sum = average(1, 2, 3, 4, 5)
print("The average is ", avg)
print("The sum is ", sum)
--- How to call a Lua Function from C
#include <stdio.h>
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
/* gcc -o luadd luadd.c -I/usr/local/include -L/usr/local/lib -llua -lm -ldl */
/* the Lua interpreter */
lua_State* L;
int luaadd ( int x, int y )
{
int sum;
/* the function name */
lua_getglobal(L, "add");
/* the first argument */
lua_pushnumber(L, x);
/* the second argument */
lua_pushnumber(L, y);
/* call the function with 2 arguments, return 1 result */
lua_call(L, 2, 1);
/* get the result */
sum = (int)lua_tointeger(L, -1);
lua_pop(L, 1);
return sum;
}
int main ( int argc, char *argv[] )
{
int sum;
/* initialize Lua */
L = lua_open();
/* load Lua base libraries */
luaL_openlibs(L);
/* load the script */
luaL_dofile(L, "add.lua");
/* call the add function */
sum = luaadd( 10, 15 );
/* print the result */
printf( "The sum is %d\n", sum );
/* cleanup Lua */
lua_close(L);
/* pause */
printf( "Press enter to exit..." );
getchar();
return 0;
}
-- add two numbers
function add ( x, y )
return x + y
end
--- How to load and call a lua function from c
//last.cc
# extern "C" {
# #include "lua.h"
# #include "lualib.h"
# #include "lauxlib.h"
# }
int main()
{
double z;
lua_State *L = lua_open();
luaL_openlibs(L);
if (luaL_loadfile(L, "last.lua") || lua_pcall(L, 0, 0, 0)) {
printf("error: %s", lua_tostring(L, -1));
return -1;
}
lua_getglobal(L, "f");
if(!lua_isfunction(L,-1))
{
lua_pop(L,1);
return -1;
}
lua_pushnumber(L, 21); /* push 1st argument */
lua_pushnumber(L, 31); /* push 2nd argument */
/* do the call (2 arguments, 1 result) */
if (lua_pcall(L, 2, 1, 0) != 0) {
printf("error running function `f': %s\n",lua_tostring(L, -1));
return -1;
}
/* retrieve result */
if (!lua_isnumber(L, -1)) {
printf("function `f' must return a number\n");
return -1;
}
z = lua_tonumber(L, -1);
printf("Result: %f\n",z);
lua_pop(L, 1);
lua_close(L);
return 0;
}
function f (x, y)
return (x^2 * math.sin(y))/(1 - x)
end
---- How to execute a Lua Script from C.
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
/* gcc -o luatest luatest.c -I/usr/local/include -L/usr/local/lib -llua -lm -ldl */
int main()
{
int s=0;
lua_State *L = lua_open();
// load the libs
luaL_openlibs(L);
//run a Lua scrip here
luaL_dofile(L,"foo.lua");
printf("\nAllright we are back in C.\n");
lua_close(L);
return 0;
}
io.write("Please enter your name: ")
name = io.read() -- read input from user
print ("Hi " .. name .. ", did you know we are in lua right now?")
---- How to get a Variable value from Lua to C.
#include <stdio.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <string.h>
/* gcc -o test test.c -I/usr/local/include -L/usr/local/lib -llua -lm -ldl */
int main()
{
lua_State *L = lua_open();
if(luaL_loadfile(L,"settings.lua") || lua_pcall(L,0,0,0))
printf("Error failed to load %s",lua_tostring(L,-1));
else
{
lua_getglobal(L,"screenWidth");
const int screenWidth = lua_tonumber(L,-1);
printf("Screen Width = %d \n", screenWidth);
lua_getglobal(L,"appName");
const char *appName = luaL_checkstring(L, -1);
printf("Screen Name = %s \n", appName);
}
lua_close(L);
/* If we got this far, everything worked */
printf("Success!\n");
return 0;
}
appName = "Firefox"
screenWidth = 400
------ How to write a lua binding in C.
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#include <string.h>
/* gcc zstring.c -Wall -shared -o zstring.so */
static int zst_strlen(lua_State *L)
{
size_t len;
len = strlen(lua_tostring(L, 1));
lua_pushnumber(L, len);
return 1;
}
int luaopen_zstring(lua_State *L)
{
lua_register(L,"zst_strlen", zst_strlen);
return 0;
}
require "zstring"
print(zst_strlen("Hello, World"))
----- Another Binding Example
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#include <unistd.h>
#include <sys/stat.h>
#include <stdlib.h>
/* gcc general.c -Wall -shared -o general.so */
/* system */
static int zst_exec(lua_State *L)
{
int status;
status = system(lua_tostring(L, 1));
lua_pushnumber(L, status);
return 1;
}
/* mkdir */
static int zst_mkdir(lua_State *L)
{
int status;
mode_t mode = lua_tonumber(L, 2);
status = mkdir(lua_tostring(L, 1), mode);
lua_pushnumber(L, status);
return 1;
}
/* symlink */
static int zst_symlink(lua_State *L)
{
int status;
const char *old = lua_tostring(L, 1);
const char *new = lua_tostring(L, 2);
status = symlink(old, new);
lua_pushnumber(L, status);
return 1;
}
/* rmdir */
static int zst_rmdir(lua_State *L)
{
int status;
status = rmdir(lua_tostring(L, 1));
lua_pushnumber(L, status);
return 1;
}
/* rename */
static int zst_rename(lua_State *L)
{
int status;
const char *old = lua_tostring(L, 1);
const char *new = lua_tostring(L, 2);
status = rename(old, new);
lua_pushnumber(L, status);
return 1;
}
/* remove */
static int zst_remove(lua_State *L)
{
int status;
const char *filename = lua_tostring(L, 1);
status = remove(filename);
lua_pushnumber(L, status);
return 1;
}
/* chown */
static int zst_chown(lua_State *L)
{
int status;
const char *filename = lua_tostring(L, 1);
uid_t owner = lua_tonumber(L, 2);
gid_t group = lua_tonumber(L, 3);
status = chown(filename, owner, group);
lua_pushnumber(L, status);
return 1;
}
/* chmod */
static int zst_chmod(lua_State *L)
{
int status;
const char *filename = lua_tostring(L, 1);
mode_t mode = lua_tonumber(L, 2);
status = chmod(filename, mode);
lua_pushnumber(L, status);
return 1;
}
/* get_current_dir_name */
static int zst_getcwd(lua_State *L)
{
char *dir;
dir = get_current_dir_name();
lua_pushstring(L, dir);
return 1;
}
int luaopen_general(lua_State *L)
{
lua_register(L,"zst_exec", zst_exec);
lua_register(L,"zst_mkdir", zst_mkdir);
lua_register(L,"zst_symlink", zst_symlink);
lua_register(L,"zst_rmdir", zst_rmdir);
lua_register(L,"zst_rename", zst_rename);
lua_register(L,"zst_remove", zst_remove);
lua_register(L,"zst_chown", zst_chown);
lua_register(L,"zst_chmod", zst_chmod);
lua_register(L,"zst_getcwd", zst_getcwd);
return 0;
}Ugggg lost all the formating in that.
If you cant make heads or tails of the above you can view it on my google code wiki http://code.google.com/p/zester/wiki/Lua_C
Last edited by zester (2011-09-13 18:20:07)
Offline
zester wrote:This would have taken me like 5 sec in Qt C++. So I wrote up the same example
in Ruby, Python, Java, Lua and Perl. And in every case my Qt C++ example was not only cleaner, shorter but easier to write/understand.on the face of it, your comparison seems completely bogus. qt isn't a language; it's an application framework.
try re-writing your examples using the relevant bindings for qt.
Yeah, that was my first thought too.
@zester
Is your opinion still the same if you write the example in C++ without using Qt?
Is your opinion still the same if you share your examples and allow the Arch Linux forum members to modify them? ![]()
The reason I use a high level language like Python is because it allows me to skip creating header files, variable declarations, deconstructors and all the other stuff that's not unique to my program, and just write my program.
Anyway, I agree, it's a fun question. ![]()
Offline
Hope you brought your flamethrowers because I am feeling a bit chilled.
Sooo I am knee deep in some heavy javascript(Nodejs) and while fighting to populate an array with the results of a sqlite query
(somehow my array is getting nuked nodejs or nodejs-sqlite3 bug?)
I am left scratching my head saying to my self WTF!! This would have taken me like 5 sec in Qt C++. So I wrote up the same example
in Ruby, Python, Java, Lua and Perl. And in every case my Qt C++ example was not only cleaner, shorter but easier to write/understand.Granted scripting languages are not only valuable but necessary in CERTAIN cases, but the way people use them today is just INSANE.
Ha, good rant
I'm of the opinion that in any given case, a person should use the programming language that is easiest for them to accomplish the given task. Scripting languages tend to be preferred mostly because you don't have to compile them and you can usually make changes to the code on the fly, leading to more rapid software development etc. but I too feel that they are a bit over-used. It seems scripting is the current 'go-to' choice for programming, and therefore I feel that people tend to use it even when an application may be better written or have better performance in a compiled language such as C/C++/Java/whatever. Personally I do most of my work in C/C++, and use scripting languages for prototyping, configuration files, and quick-n-dirty helper scripts for auto-generating code, so on that note I don't feel that scripting languages should be written off completely. It's just a matter of using the best tool for the current application.
Hofstadter's Law:
It always takes longer than you expect, even when you take into account Hofstadter's Law.
Offline
Hope you brought your flamethrowers because I am feeling a bit chilled.
Sooo I am knee deep in some heavy javascript(Nodejs) and while fighting to populate an array with the results of a sqlite query
(somehow my array is getting nuked nodejs or nodejs-sqlite3 bug?)
I am left scratching my head saying to my self WTF!! This would have taken me like 5 sec in Qt C++. So I wrote up the same example
in Ruby, Python, Java, Lua and Perl. And in every case my Qt C++ example was not only cleaner, shorter but easier to write/understand.Granted scripting languages are not only valuable but necessary in CERTAIN cases, but the way people use them today is just INSANE.
My primary scripting language is javascript but that is only because my work requires it. But ill take lua over any scripting language any day.I am going to go sink my teeth in Django see if that pisses me off any less!
Sooo whats your opinion.
Out of all of the languages you listed, only Lua and JavaScript are real scripting languages.
Please learn the difference between a high level language (Like OCaml) and a scripting language (Like Lua).
Particularly, some languages are intended to script other programs (Of course both Javascript and Lua are both fully turing-complete programming languages, but you wouldn't use them like general purpose languages most of the time)
Last edited by Nisstyre56 (2011-09-15 23:44:48)
In Zen they say: If something is boring after two minutes, try it for four. If still boring, try it for eight, sixteen, thirty-two, and so on. Eventually one discovers that it's not boring at all but very interesting.
~ John Cage
Offline