lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


When i am writing lua script I always have some
code in the beginning of script like this 

-- string 
local fmt = string.format
local sub = string.sub
local sub = string.gsub
-- math
local abs = math.abs
local int = math.floor
local sgn = function(n)   return
(n==0)and(0)or(n>0 and 1 or -1) end
local fix = function(n)   return
math[(n>0)and"floor"or"ceil"](n) end
local mod = function(n,d) return n - d*int(n/d)
end
local num = function(n)   return ((n==nil)and 0
or n) end
local amid = function(x,a,b) return (a<x)and(x<b)
end
...

so that there is less typing and function are
declare as local, much faster.

may be it is easier if we have a #include feature
like in C example

#include "stringmacro.lua"
#include "mathmacro.lua"
...

yes you can use the loadfile function, example

loadfile "stringmacro.lua"
loadfile "mathmacro.lua"
 
But you have to declare the function as global
right, local declaration is faster than global.


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com