Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Lua ➜ require ("xxx") problem

require ("xxx") problem

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Tkl1129   Hong Kong  (43 posts)  Bio
Date Tue 10 Jan 2012 07:13 AM (UTC)
Message
While I'm writing a code...
The case I have to access 2 .lua files..

1. db_map.lua (Contain the Map data in Lua table format)
2. f_path.lua (Contain the function code for path function)

normally when I write a code, I will start with require


function path_gen(a,b)
require("db_map")

local x = a
local y = b
local x1 = string.gsub(x,"%d+","")
local y1 = string.gsub(y,"%d+","")

local p_back = Map[x1][x].Back
local p_a1 = Map[x1][x].Path
local p_a2 = Map[y1][y].Path
local p_go = Map[y1][y].Go

print(p_back)
print(p_a1)
print(p_a2)
print(p_go)

end


This works...but what if I want to add other function into this code , the code was store inside the "f_path.lua"

When I add

function path_gen(a,b)
require("db_map")
require("f_path")

local x = a
local y = b
local x1 = string.gsub(x,"%d+","")
local y1 = string.gsub(y,"%d+","")

.......
............
local z = path_mix(x,y)



The function "path_mix" was store inside f_path, when I run this code, it occur error said f_path.lua not found...

so strange, cannot run 2 x lua file at the same time?
how it solve or write code in otherway? Thanks.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #1 on Tue 10 Jan 2012 07:21 PM (UTC)
Message
Where are these two .lua files stored? In the same place as each other? What is that place?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Tkl1129   Hong Kong  (43 posts)  Bio
Date Reply #2 on Wed 11 Jan 2012 01:05 AM (UTC)
Message
inside the lua folder

when I run "db_map"...inside are Lua table data...
it's work

or I seperate run the "f_path"...inside are functions...
it's work too

but when I run


require("db_map")
require("f_path")


the code when run the function which inside "f_path", it return "nil"....

so wanna ask is that not appropriate to run 2 lua together? or have another method like "module"
Top

Posted by Fiendish   USA  (2,558 posts)  Bio   Global Moderator
Date Reply #3 on Wed 11 Jan 2012 01:53 AM (UTC)
Message
I do multiple requires all the time. Does one of your required files change the working directory?

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Tkl1129   Hong Kong  (43 posts)  Bio
Date Reply #4 on Wed 11 Jan 2012 02:00 AM (UTC)
Message
so strange,
maybe I try to do more testing first.

By the way, do all functions keep in *.lua good?
or maybe use "module" function is more easy to manage?

just want to share and learn you guys's preference..thanks.
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


18,839 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.