Author Topic: [Request]How to: do various things with files.  (Read 2595 times)

0 Members and 1 Guest are viewing this topic.

Offline Jaras

  • Member
  • ***
  • Posts: 37
  • Karma: +0/-0
[Request]How to: do various things with files.
« on: 08 May, 2004, 15:51:50 »
if there's someone, who could spend some time for writing such guide i'd be wery grateful. generally file operations are easy, but i found major problems with format of read data. when i read a line and then put in strfind =, ptoka says, that #1 argument is a table, not expected string, but before strfind i'm writing type() of that variable and type returns that's a string. i don't have any idea, what could be wrong so i'm asking for help.
« Last Edit: 08 May, 2004, 15:53:26 by Jaras »

PtokaX forum

[Request]How to: do various things with files.
« on: 08 May, 2004, 15:51:50 »

[NL]Pur

  • Guest
(No subject)
« Reply #1 on: 08 May, 2004, 16:28:35 »
can you post the script that way we can help

Offline Jaras

  • Member
  • ***
  • Posts: 37
  • Karma: +0/-0
(No subject)
« Reply #2 on: 08 May, 2004, 22:43:36 »
Code: [Select]
function GoodIP( user )
readfrom( IPsFile )
while 1 do
local line = read()
if not( line == nil ) or ( line == "" ) then
user:SendData( BotName, line.." - "..type( line ) )
if strfind( line, "(.+)%s=%s" ) == user.sNick then
user:SendData( BotName, line )
if strfind( line, "%s=%s(.+)$" ) == user.sIP then
readfrom()
return 1
else
readfrom()
return nil
end
end
else
readfrom()
return 0
end
end
end

IPsFile:
Code: [Select]
Jaras = 82.66.66.66
emu = 82.77.77.77

it's based on cSlave, coz i'm still learning. SendData are there for debuggin'.
« Last Edit: 08 May, 2004, 22:45:01 by Jaras »

Offline plop

  • Forum God
  • ****
  • Posts: 2 464
  • Karma: +37/-0
(No subject)
« Reply #3 on: 08 May, 2004, 23:39:10 »
try like this.
Code: [Select]
function GoodIP( user )
readfrom( IPsFile )
while 1 do
local line = read()
if not( line == nil ) or ( line == "" ) then
user:SendData( BotName, line.." - "..type( line ) )
         local s,e,tmp = strfind( line, "(.+)%s=%s" )
if tmp == user.sNick then
user:SendData( BotName, line )
            local s,e, tmp2 = strfind( line, "%s=%s(.+)$" )
if tmp2 == user.sIP then
readfrom()
return 1
else
readfrom()
return nil
end
end
else
readfrom()
return 0
end
end
end
the strfind you posted above returns 1 if the pattern matches something.
this means it never can be equal 2 and ip or name.

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Offline Jaras

  • Member
  • ***
  • Posts: 37
  • Karma: +0/-0
(No subject)
« Reply #4 on: 09 May, 2004, 18:00:15 »
i tried giving to a variable strfind value with the same result. i'll try your way, but i don't want to copy i want to understand. i thought that i understood cSlave's method, but it didn't work, that's why i asked for guide.

of course thank you kindly for help  :D
« Last Edit: 09 May, 2004, 18:02:42 by Jaras »

Offline plop

  • Forum God
  • ****
  • Posts: 2 464
  • Karma: +37/-0
(No subject)
« Reply #5 on: 09 May, 2004, 19:43:14 »
Quote
Originally posted by Jaras
i tried giving to a variable strfind value with the same result. i'll try your way, but i don't want to copy i want to understand. i thought that i understood cSlave's method, but it didn't work, that's why i asked for guide.

of course thank you kindly for help  :D
s,e,tmp = strfind( line, "(.+)%s=%s" )
=
returns_1_if_found,returns_the_location_if_found,returns_what_is_found = strfind(data, ..........etc

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Offline NotRabidWombat

  • Lord
  • ***
  • Posts: 384
  • Karma: +2/-0
(No subject)
« Reply #6 on: 09 May, 2004, 19:59:27 »
Almost.

"strfind (s, pattern [, init [, plain]])
Looks for the first match of pattern in s. If it finds one, then strfind returns the indices of s where this occurrence starts and ends; otherwise, it returns nil. If the pattern specifies captures (see gsub below), the captured strings are returned as extra results. A third, optional numerical argument init specifies where to start the search; its default value is 1, and may be negative. A value of 1 as a fourth, optional argument plain turns off the pattern matching facilities, so the function does a plain ``find substring'' operation, with no characters in pattern being considered ``magic''. Note that if plain is given, then init must be given too."

http://www.lua.org/manual/4.0/manual.html

-NotRabidWombat


I like childish behavior. Maybe this post will be deleted next.

Offline Jaras

  • Member
  • ***
  • Posts: 37
  • Karma: +0/-0
(No subject)
« Reply #7 on: 09 May, 2004, 23:26:25 »
Quote
Originally posted by plop
Quote
Originally posted by Jaras
i tried giving to a variable strfind value with the same result. i'll try your way, but i don't want to copy i want to understand. i thought that i understood cSlave's method, but it didn't work, that's why i asked for guide.

of course thank you kindly for help  :D
s,e,tmp = strfind( line, "(.+)%s=%s" )
=
returns_1_if_found,returns_the_location_if_found,returns_what_is_found = strfind(data, ..........etc

plop

damn. how could i've forgotten???

Offline Jaras

  • Member
  • ***
  • Posts: 37
  • Karma: +0/-0
(No subject)
« Reply #8 on: 11 May, 2004, 01:01:58 »
sry 4 doublepost, but i just realized how dumb i am. you made me believe, that i've got problems with using strfind function (and it was stupid mistakes), but i was asking bout strfind itself, not how to use it. short flashback: i'm reading a line from file and putting it into strfind as firts argument. before that i'm writing type() of variable holding this line. it returns, that variable's type is string, but ptoka says, that #1 argument in strfind got table, when string was expected. so this is main problem. can anyone help? again - i've started new thread, coz i want to understand it, not learn it.

PtokaX forum

(No subject)
« Reply #8 on: 11 May, 2004, 01:01:58 »