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

Programming languages that don't suck

Name: Anonymous 2009-11-22 15:41

Lisp, Scheme and Haskell are the obvious ones. JavaScript is a nice language. C always has its place. C# might be the jewel of enterprise.

What else is there that /prog/ recommends? I've heard good things about ML. A language that seems interesting from its Wikipedia page is Self, but I'm not too sure about it.

Name: Anonymous 2009-11-23 14:02

[expert]
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>

static int ipairsaux (lua_State *L) {
  int i = luaL_checkint(L, 2);
  luaL_checktype(L, 1, LUA_TTABLE);
  if (i == -1) {
    lua_pushinteger(L, 0);
    lua_rawgeti(L, 1, 0);
  } else {
    i++;
    lua_pushinteger(L, i);
    lua_rawgeti(L, 1, i);
  }
  return (lua_isnil(L, -1)) ? 0 : 2;
}

static int zeroindex_ipairs (lua_State *L) {
  luaL_checktype(L, 1, LUA_TTABLE);
  lua_pushvalue(L, lua_upvalueindex(1));
  lua_pushvalue(L, 1);
  lua_pushinteger(L, -1);
  return 3;
}

char* derp = "t = {[0]='a','b','c','d','e','f'}; for k,v in ipairs(t) do print(k,v); end";

int main(int argc, char** argv) {
    lua_State* L = luaL_newstate();
    luaL_openlibs(L);

    lua_pushvalue(L, LUA_GLOBALSINDEX);
    lua_pushcfunction(L, ipairsaux);
    lua_pushcclosure(L, zeroindex_ipairs, 1);
    lua_setfield(L, -2, "ipairs");

    luaL_loadstring(L, derp);
    lua_call(L, 0, 0);

    return 0;
}
[/expert]

Newer Posts