zoukankan      html  css  js  c++  java
  • lua 中的 loadfile、dofile和require的调用

    文件 hello.lua

    print("hello")
    function say()
        print("hello world")
    end

    1. 介绍:

    dofile: 读入代码文件并编译执行。每调用dofile一次,都会重新编译执行一次。

    loadfile: 编译代码,将整个模块文件当成一个函数返回,但是不执行代码。

    require: 在加载一个.lua文件时,require会先在package.loaded中查找此模块是否存在,如果存在,直接返回模块。
    如果不存在,则加载模块文件。

    2. 安全调用

    math_func = {}
    
    function math_func.Sum(a, b)
        return a + b
    end
    
    function math_func.Fac(n)
        if n <= 1 then
            return n
        end
        return n * math_func.Fac(n-1)
    end
    
    return math_func
  • 相关阅读:
    bzoj1098 1301
    bzoj3237
    bzoj3170
    bzoj4008
    一些题解
    bzoj4028
    bzoj3196
    redis学习
    quartz学习
    电商618 压测、优化、降级预案
  • 原文地址:https://www.cnblogs.com/spaceapp/p/10319162.html
Copyright © 2011-2022 走看看