[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  require ("xxx") problem

require ("xxx") problem

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


Posted by Tkl1129   Hong Kong  (43 posts)  [Biography] 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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,989 posts)  [Biography] 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
[Go to top] top

Posted by Tkl1129   Hong Kong  (43 posts)  [Biography] 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"
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] 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
[Go to top] top

Posted by Tkl1129   Hong Kong  (43 posts)  [Biography] 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.
[Go to top] 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.


13,578 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]