Category: Lua
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
This may not work if your lua-include is not in the path for compiling.
And you'll run into such error messages:
2
3
4
5
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.
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!
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.
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
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
<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!
Finished first version of luainfo()
Since its available for php as phpinfo I made a luainfo.lua for lua, too.
It shows loaded packages, response vars and other server variables.
Grab a preview in this rendered html file and grab the MIT-licensed luainfo.lua source.
Convert Title-String to Url Slug in PHP or Lua
When making your urls looking better, you may want to convert a title to a url-slug.
An url-slug is in common a string containing only alphanumeric letters and '-'. Following php and lua function converts it to that format.
php:
2
3
return str_replace(" ","-",ereg_replace("[ ]+"," ",ereg_replace("[^ A-Za-z0-9]","",$str)));
}
lua:
2
3
return string.gsub(string.gsub(str,"[^ A-Za-z]",""),"[ ]+","-")
end
The toSlug function also replaces multiple spaces with one '-' only.
You can find this Lua-How-To at luanet.net, too.


