Detail of lua can be read here
There are 2 ways to include function from lua file to another lua file.
To explain the ways, we will use this schema:
there must be at least 2 file, here we use
1. caller.lua ; lua file from where we call other file function.
2. called.lua ; file where called function reside.
here the code for caller.lua:
function main()
print("main called")
end
main()
Here the code for called.lua:
function called()
print("i am called")
end
The Ways
A. First way, Using require
By using require, our called file must be resided in the same path with the caller file. If the called file not in the same path, lua will throwing some error. If we want the called file work, we must place the called file in lua library path. There is nothing needed to change in called.lua. We only need to change called.lua.
Here the code for caller.lua
require "called"
function main()
print("main")
called()
end
B. Second way, Using dofile
dofile working like require with exception that we need to use the full path of the called file. The benefit of using loadfile is we can call called file from another directory of the caller file. There is nothing needed to change in called.lua. We only need to change called.lua.
Here the code for caller.lua
require "PATH_OF_CALLED_FILE/called.lua"
function main()
print("main")
called()
end
PATH_OF_CALLED_FILE is the path of the called.lua
For detail of using require and dofile, please with http://www.lua.org/
Category
- Android (42)
- Android Studio (1)
- Android Tips (5)
- Assembly (3)
- Bash (1)
- Basic (1)
- berita (16)
- Biology (5)
- Bisnis (1)
- C++ (2)
- Canvas (1)
- Christianity (3)
- Database (8)
- Donation (1)
- Ebook (8)
- Editor (1)
- Email (1)
- Free (2)
- gambar (3)
- Game (3)
- Gradle (1)
- Graphic (2)
- Gratis (1)
- handphone (1)
- hidupku (106)
- How To (41)
- Icon (2)
- informasi (49)
- Internet (2)
- Introduction to Programming Using Java (6)
- Java (9)
- Kaizen (1)
- Kata-kata bijak (43)
- Kata-kata Motivasi (46)
- Kesehatan (4)
- Library (1)
- LibreOffice (1)
- Linux (17)
- lua (2)
- Manga (1)
- mediawiki (1)
- Mitos (4)
- Motivasi (51)
- Motivation (12)
- musicXML (1)
- Musik (3)
- My Life (7)
- Myth (1)
- Networking (5)
- OOP (1)
- OpenDocument (1)
- Opini (84)
- Opinion (5)
- Otak (2)
- pemrograman (42)
- pemrograman visual (18)
- Pengembangan Diri (28)
- Pengenalan Pemrograman Menggunakan Java (7)
- Pengetahuan dasar (1)
- Personal Building (34)
- PHP (1)
- Printer (3)
- Programming (1)
- Qt (4)
- Quote (1)
- Review (2)
- Saran (2)
- Science (1)
- Script (1)
- Security (2)
- Sistem Informasi (11)
- Situs (4)
- Slackware (20)
- Social (2)
- Software (28)
- SQLite (1)
- Teknologi (2)
- thunderbird (1)
- Tips (1)
- Tumbuhan (2)
- Tutorial (15)
- Video (2)
- virus (2)
- Visual Basic 6 (5)
- Windows (8)
- Windows 10 (1)
- Windows 8 (2)
- Wise Agenda (41)
Diberdayakan oleh Blogger.
Senin, 10 Maret 2014
How to include function in lua file from another lua file
by Unknown | 
in pemrograman
at Senin, Maret 10, 2014
- Pencampuran semua warna menghasilkan warna apa?
- Konversi Pound (Lbs) ke Kg
- Setting DHCP Server pada ZTE F660 (ZXHN F660)
- 5 Mesin Pencari Buku
- benarkah Combantrin bisa menyembuhkan sakit gigi?
- Port Forwarding di ZTE f660
- Mengatasi The Panel key is locked Sony 3LCD Projector
- Arti Songong
- Membaca bersuara atau membaca diam?
- Biji Terkecil dan Biji Terbesar Di Dunia
0 comments:
Silahkan tinggalkan komentar anda: