Category: Lua

rss

Lua Implementation of OAuth

Since twitter stopped supporting basic auth, some are searching for a lua implementation of oauth.

A while back (in last 2009) I wrote a library for exactly this, but didn't finished it. So I took some time to polish it up and it works still great ;-).

So have fun with the MIT licensed lua oauth library download or source at github.

In open source & Lua By DracoBlue @ 21:50 16.09.2010

Refreshing workspace to recover changes ... crash

Since I am using lunareclipse-plugin + eclipse 3.2 for lua development, I sometimes face the problem (when my pc got switched off too early when trying to hibernate) that eclipse does nothing but crashing when I try to start it.

Log states something like that:

1
2
3
!ENTRY org.eclipse.core.resources 2 10035 2009-06-30 22:19:06.772
!MESSAGE The workspace exited with unsaved changes in the previous
session; refreshing workspace to recover changes.

... and crashs.

I managed to make it working again, by heading to the workspace directory.

workspace\.metadata\.plugins\org.eclipse.core.resources and removing the file .snap.

In Lua & Eclipse By DracoBlue @ 22:26 30.06.2009

Fixing compiling issues with magnet.c

Jan Kneschke maintains lighttpd and posted a simple FCGI for lua. This magnet.c should be easily compiled with

1
gcc -Wall -O2 -g -o magnet magnet.c -llua5.1 -lfcgi -ldl -lm

This may not work if your lua-include is not in the path for compiling.

And you'll run into such error messages:

1
2
3
4
5
magnet.c:3:20: error: lualib.h: No such file or directory
magnet.c:4:21: error: lauxlib.h: No such file or directory
magnet.c:11: Error: expected »)« before »*« token
magnet.c:19: Error: expected »)« before »*« token
magnet.c:59: Error: expected »)« before »*« token

Since you may not be used to compiling, I think it might be good to post a reason for that and a solution.

The reason is, that lualib.h is not in include path. To add it specific folder for the compiling to the include path you may use the -I /path/name/ parameter.

1
gcc -Wall -O2 -g -o magnet magnet.c -I/usr/include/lua5.1/ -llua5.1 -lfcgi -ldl -lm

There are some distributions, where the -llua5.1 may not work and result in cannot find -llua5.1. In this cases try -llua instead.

Have fun compiling!

In open source & Lua By DracoBlue @ 21:28 19.03.2009

PawnDoc 0.1 released

Today I finished PawnDoc 0.1. You may download PawnDoc at the official PawnDoc wiki page.

The tool PawnDoc is a tool for the Pawn language similar to JavaDoc for Java. With pawndoc-comments in your pawn sourcecode you can generate documentation-html-files and even wiki-syntax! See dprop.inc.wiki.txt or dprop.inc.html as example (source .pwn).

You can also find a welcome post at samp forums. PawnDoc is written in Lua 5.1.

In open source, Lua, pawn & PawnDoc By DracoBlue @ 13:25 13.12.2007

DModule 0.13 finished

Today I got the first update of DModule for you guys. DModule 0.13 contains again some cool new features, like enchanced pawn-doc reader and a completely new command line interface to dmodule project managment! Very handy if you want to check what modules your project chooses from which directory or if you want to add modules on the fly.

Also it contains a bugfixed version of GetPlayerTeam and SetPlayerTeam (and the Spawn-Functions) to fix the issues with friendly fire in SA-MP.

Here is the detailed list of changes, also available in the Changelog:

  • Added bugfixed version of SetPlayerTeam, GetPlayerTeam, SetSpawnInfo and AddPlayerClass(Ex) to provide working friendly fire in samp.
  • Added commandline interface for project management
  • Updated the pwn-doc reader

    • able to read @param type varname description
    • reading params_def correctly
    • removing &'s and & from param name

  • Ships now with

    • dini 1.5.2
    • dcmd
    • timestamp
    • dplayers 1.1
    • dsystem 1.0
    • dutils 1.11
    • inouticon 1.0
    • inoutmsg 1.0
    • killlist 1.0
    • killpunish 1.0
    • killreward 1.0
    • loginout 1.0
    • modeconfig 1.0
    • teamspawn 1.1

In open source, Lua, pawn & DModule By DracoBlue @ 21:50 11.12.2007

Fast in_array or in_list implemented Lua?

On lua mailing list somebody asked if there is any way to check very short if an element is in a specific list of elements.

In php you would do for example

1
if (in_array("A",array("A","B","C")) ) { echo "hello"; }

<p style="margin: 5px">Of course, everyone can write a short in_table function in <!--more-->lua:</p>

<pre class="geshi"><span style="color: #000000; font-weight: bold">function</span> in_table <span style="color: #66cc66">(</span> e, t <span style="color: #66cc66">)</span>
<span style="color: #000000; font-weight: bold">for</span> _,v <span style="color: #000000; font-weight: bold">in</span> <span style="color: #a3209f; font-weight: bold">pairs</span><span style="color: #66cc66">(</span>t<span style="color: #66cc66">)</span> <span style="color: #000000; font-weight: bold">do</span>
<span style="color: #000000; font-weight: bold">if</span> <span style="color: #66cc66">(</span>v==e<span style="color: #66cc66">)</span> <span style="color: #000000; font-weight: bold">then</span> <span style="color: #000000; font-weight: bold">return</span> <span style="color: #000000; font-weight: bold">true</span> <span style="color: #000000; font-weight: bold">end</span>
<span style="color: #000000; font-weight: bold">end</span>
<span style="color: #000000; font-weight: bold">return</span> <span style="color: #000000; font-weight: bold">false</span>
<span style="color: #000000; font-weight: bold">end</span></pre>
But Asko answered a clever and very short way:

if ({A=1,B=1,C=1})["A"] then print("hello") end

Why does that work?

{A=1,B=1,C=1} creates nothing but a table with following style:

[A] => 1
[C] => 1
[B] => 1

(used print_r for lua here)

So what does ({A=1,B=1,C=1})["A"] do then? It returns the value of the table's ["A"]-Field. And this is 1! Thatswhy the 'then'-branch will be used.

Basicly its using lua's all table entries are set or nil way to check wether a element is set as key in the temporary table or not.

So if you use your own lua implementation for in_table or do it that tricky way is your choice!

In open source & Lua By DracoBlue @ 21:41 11.11.2007