The online racing simulator
There's nothing that will allow you to do that right.. But I can't see why you would want to?
E.g. you bind the same function to several events. Sometimes it could prevent you to create duplicities of code:
function RST_and_LAP (event, imsg)
common code for rst and lap
if (event = ISP_RST) then
rst specific code
end
another common code for rst and lap
if (event = ISP_LAP) then
lap specific code
end
yet another common code for rst and lap
end
evt_bind(ISP_RST, RST_and_LAP)
evt_bind(ISP_LAP, RST_and_LAP)

In the current version you would need two functions with almost the same code. On the other hand, I don't think, that this is one of the most important features missing. But good to notice for the future, though .
But surely you'd separate the common code into its own function? Theres nothing to stop you doing that..
You're right, but these fuctions with a common code could be short (e.g. one condition) and the situation could get more complicated, when you bind the same function to three and more events. Anyway, its more about individual coding style than a functionality missing. I'm just guessing the examples, maybe A.Fedorov has already a better one.
i do some script. Program RaceManager (python scripts) do laps.log file which contain data

20070508 16:24:19,SAtaN,BL1,SAtaN666,XRR,338,3:35.380,2:43.840,3:12.120
20070511 10:56:39,demon,BL1,,FXR,4,1:31.340,0:33.520,1:02.520
20070511 11:11:36,demon,BL1,,FXR,5,11:05.160,0:33.130,1:02.960
20070511 11:13:00,demon,BL1,,FXR,6,1:23.600,0:29.140,0:58.430
20070511 19:58:15,UnDeAD,BL1,835,RB4,1,2:08.780,1:01.040,1:36.670
20070512 14:44:49,MDK,BL1,373,FXR,28,1:33.110,0:35.860,1:06.050

construction
date time,uname (not pname),track,plate,cname,lapsdone,ltime,sp1[,sp2,sp3]

I maked stats (php) using this file. Now i have all without uname and track (lapsdone left stats). This is my script (not accomplished)


function ca(imsg)
luaLFS:tiny(1, TINY_NPL)
end

evt_bind(EVT_CONNECTED, ca)




function put_massive(imsg)
local t = luaLFS:npl(imsg)
s = { [t.plid] = { user = "", track = "", plate = t.plate, car = t.cname, sp1 = 0, sp2 = 0, sp3 = 0} }
print("Car: "..s[t.plid].car)
print("Plate: "..s[t.plid].plate)
end

evt_bind(ISP_NPL, put_massive)



function l_split(imsg)
local t = luaLFS:spx(imsg)
if (t.split == 1) then
s[t.plid].sp1 = t.stime
print ("SP1="..s[t.plid].sp1)
end

if (t.split == 2) then
s[t.plid].sp2 = t.stime
print ("SP1="..s[t.plid].sp1)
print ("SP2="..s[t.plid].sp2)
end
if (t.split == 3) then
s[t.plid].sp3 = t.stime
print ("SP1="..s[t.plid].sp1)
print ("SP2="..s[t.plid].sp2)
print ("SP3="..s[t.plid].sp3)
end
end

evt_bind(ISP_SPX, l_split)



function l_lap(imsg)
local t = luaLFS:lap(imsg)
local file_w = io.open("D:/Downloads/LFS/luaLFS-0.7/scripts/laps.log","a")
file_w:write(os.date('%x %X').." "..s[t.plid].plate.." "..s[t.plid].car.." "..t.ltime.." "..s[t.plid].sp1.." "..s[t.plid].sp2.."\n")
file_w:close()

end

evt_bind(ISP_LAP, l_lap)

i find only one way how get uname because uname not linked with plid. create table

local t = luaLFS:ncn(imsg)
n = { [t.pname] = t.uname }


then insert

local t = luaLFS:npl(imsg)
s[t.plid].user = n[t.pname]


something else way how get uname?

Tables more and more with connecting new people. If people are disconnected it is necessary to clean unused tables. As this do?
like laps.log from RaceManager
Updated

This is almost complete script. It use new api function and some small fix old api.

work with AI
work with more than one player
Attached files
lapslog-0.3.zip - 1.1 KB - 302 views
Nice work A.Fedorov - I'll pop your additions into trunk and add you to the various notice files
I try test with 2 players. Only last connected player data put in laps.log
Please test (if you can).
From a 10 second look at the logs source, s is never defined as a table. Try adding
s = { }

at the top of the code and see if it helps
For those interested in updates, I'm working on backporting some stuff from my development version into what will become 0.8;
* A generic sockets library - which will allow for things like LFSW / HTTP clients, etc. Currently it's blocking, like all scripts, and I'm considering how I want to approach that issue right now as it can become an issue in large scripts.
* I've integrated the lbitlib.c library by Reuben Thomas to provide bitwise ops. Unfortunately without patching lua itself theres not much choice.
* I've changed how the luaLFS object is created and how the API hooks into this. Basically i register the luaLFS object from within the C source, and then the rest of the "functions" get tacked on afterwards. This makes a few things easier to use and moves things like rehash / sleep / kill into their own "namespace" or pseudo-object. Whatever you want to call it (library in lua terms).
* Integrated the API updates from A.Fedorov and updated the NOTICE file. I'll be finishing the rest of the API in this release as well.
* I'm considering bundling an SQL engine of some form. I'm likely to opt for SQLite for various reasons, but I'm not yet fully decided.
* I'm going to bundle an updated versions of all the example scripts, including undercontrol, seen and a few others.

I think that's it

Beware, the following maybe a little more dense if you're unfamiliar with the background code in luaLFS;
Multi-threading has gone on the back burner for now, but it's an issue, especially for concurrency in running the scripts and keeping the insim connection alive. On the plus side the whole thing should be pretty much thread safe now and I'm yet to see any shared memory issues in the pthreaded version. Unfortunately my version isn't actually running a thread for sockets and lua, but a thread for each insim connection and lua state.
api
Updated

not yet full api, but more functions
NEED TESTING all functions

API 0.1X10

[*] fix ISP_SMALL, ISP_MOD
----------------------------------------------------------
API 0.1X3
[+] TINY_AXI, TINY_AXC (file event_id.lua)
[+] ISP_AXI, ISP_AXO

[*] ISP_NPL (byte Model)
----------------------------------------------------------
API 0.1X
[+] ISP_BTN (tested), ISP_BTC, ISP_BTT

all variables look into InSim.txt
Attached files
event_id.zip - 760 B - 274 views
api_x10.zip - 3.2 KB - 285 views
Update lapslog (above). Now all work fine it seems.
Print Yellow Flag.

require last api
Attached images
yellow_flag.jpg
Attached files
yellow_flag.zip - 572 B - 291 views
I could release 0.7.1 if you want me to, with the updated APIs bundled (it would only be updated APIs). I'm not going to release 0.8 until I've finished the HTTP object and LFSW query script though, as its something people have been asking for a lot. I intend to finish that this weekend, but something has just popped up to make me question whether or not I'm going to have time..
1. I not finded function in lua like pause()/wait()/sleep(). My function pause() - brake server

function pause(time)
local time0 = os.time()
while (os.difftime(os.time(), time0) < time) do
end
end

2. How can i get position of all cars? Please give me example.
Quote from A.Fedorov :1. I not finded function in lua like pause()/wait()/sleep(). My function pause() - brake server

There is one included in 0.7 - luaLFS_sleep() - it is blocking though so what you want to do is spawn a new thread for things which are going to pause. I believe there is an example somewhere in the programmers section. Unfortunately I'm not at home right now so I cant actually lay my hands on it - as the example is not in SVN.

Quote from A.Fedorov :2. How can i get position of all cars? Please give me example.

MCI or NLP packets need to be turned on - in 0.7 this can only be done by recompiling luaLFS - however this is fixed in the next release, which I will roll with a number of updates (but not all that I wanted) when I return home on Monday night / Tuesday
luaLFS 0.8

Quick release which introduces a few fundamental fixes and things which should've been included for a long time.

Beware this release will break existing scripts - but there is an easy fix (see changes below)

Changes:
* luaLFS object within the Lua scripts is now created by the executable itself, not within the script, it's then modified to add the API functions to it. What this means is that if you use luaLFSapi:functionname by accident, it won't work.
* luaLFS_* functions no longer "work", but can be used by replacing with luaLFS.* (i.e. luaLFS_sendmsg is now luaLFS.sendmsg, luaLFS_sleep is now luaLFS.sleep, etc.)
* You can now tell if luaLFS is in verbose mode (luaLFS.verbose returns 1 if it is)
* Flags configuration in config.lua now works thanks to the bundled bitwise library (see NOTICE file for details). Example of usage in config.lua.
* Updated event ids to include ISI flags for usage in flags configuration
* Updated API - now almost all of the insim packets are there - a big thank you to A.Fedorov for that
* Fixed a bug connected with timeouts under Windows 2003 R2

Things missing from this release:
* No LFSW Querying - I've stripped out the socket code
* No decide example scripts
* No SQL bundled
* No path argument (still)
fix function luaLFSapi:small
local omsg = bpack("bbbbL", 8, ISP_SMALL, reqi, subt, uval)

fix function luaLFSapi:mod
local omsg = bpack("bbbbllll", 20, ISP_MOD, 0, 0, bits, rr, width, height)
Thanks A.Fedorov I've fixed this in my version and I'll ammend the 0.8 zip shortly
need test with many cars on track
function luaLFS:mci(imsg)
-- print("Parsing MCI")
-- local n, psize, pty, reqi, numc, compcar = bunpack(imsg, "bbbb A?")
local n, psize, pty, reqi, numc = bunpack(imsg, "bbbb")
imsg = string.sub(imsg, 5)

-- ALWAYS string.len(imsg)/28 == numC ??????
---------------------------------------------
local i
local compcar = {}
for i = 1, string.len(imsg)/28 do
local n, node, lap, plid, position, info, sp3, x, y, z, speed, direction, heading, angvel = bunpack(imsg, "HHbbbblllHHHh")
compcar[plid] = { node = node, lap = lap, position = position, info = info, x = x, y = y, z = z, speed = speed, direction = direction, heading = heading, angvel = angvel }
imsg = string.sub(imsg, 29)
end
-- print("MCI parsed")
return { compcar = compcar }
end

use in script something like this

local mci = luaLFS:mci(imsg)
...
[I]plid[/I] = ...
print(mci.compcar[[i]plid[/i]].node)

I've not tested this, but I *think* it should work:

function luaLFS:mci(imsg)
local n, psize, pty, reqi, numc = bunpack(imsg, "bbbb")
local q, compcararr = bunpack(imsg, "A"..28*numc, n)
local compcar = { }

local i, s
s = 0
for i = 1, numc do
local node, lap, plid, position, info, sp3, x, y, z, speed, direction, heading, angvel
s, node, lap, plid, position, info, sp3, x, y, z, speed, direction, heading, angvel = bunpack(imsg, "HHbbbblllHHHh", s)
compcar[plid] = { node = node, lap = lap, position = position, info = info, x = x, y = y, z = z, speed = speed, direction = direction, heading = heading, angvel = angvel }
end
return { numc = numc, compcar = compcar }
end

Thanks. Your function is compacted
fixed

function luaLFS:mci(imsg)
local n, psize, pty, reqi, numc = bunpack(imsg, "bbbb")
local q, compcararr = bunpack(imsg, "A"..28*numc, n)
local compcar = { }

local i, s
s = 1
for i = 1, numc do
local node, lap, plid, position, info, sp3, x, y, z, speed, direction, heading, angvel
s, node, lap, plid, position, info, sp3, x, y, z, speed, direction, heading, angvel = bunpack(compcararr, "HHbbbblllHHHh", s)
compcar[plid] = { node = node, lap = lap, position = position, info = info, x = x, y = y, z = z, speed = speed, direction = direction, heading = heading, angvel = angvel }
end
return { numc = numc, compcar = compcar }
end

I've quickly done the IS_NLP packet for those that may be interested (untested). I'll roll 0.8.1 this afternoon with the updated API.

function luaLFS:nlp(imsg)
local n, psize, pty, reqi, nump = bunpack(imsg, "bbbb")
local q, nodelaparr = bunpack(imsg, "A"..6*nump, n)
local nodelap = { }

local i, s
s = 1
for i = 1, nump do
local node, lap, plid, position
s, node, lap, plid, position = bunpack(nodelaparr, "HHbb", s)
nodelap[plid] = { node = node, lap = lap, position = position }
end
return { nump = nump, nodelap = nodelap }
end

Also a fixed, but very untested updated IS_REO (bidirectional):
function luaLFS:reo(...)
if (arg[n] == 1) then
-- Receiving IS_REO
local n, psize, pty, reqi, nump, plid = bunpack(arg[1], "bbbbb32")
return { nump = nump, plid = plid }
elseif (arg[n] == 3) then
-- Sending IS_REO
-- To use: luaLFS:reo(reqi, nump, tableofplid)
local plids, i
i = 1
for i, arg[2] do
plids = plids..bpack("b", arg[2][i])
end
local omsg = bpack("bbbbA32", 36, ISP_REO, arg[1], arg[2], plids)
luaLFS.sendmsg(omsg, string.len(omsg))
else
error("Invalid arguments")
end
end


FGED GREDG RDFGDR GSFDG