Use of loadstring () in Lua

Source: Internet
Author: User

Lua loadstring

Similar to loading, you can obtain a block from a given string.
To load and run a given string


It is generally used as follows:

Assert (loadstring (SCRIPT ))()

F = loadstring ("A = 1 ")
Equivalent:
F = loadstring ("function () A = 1 End ")

Complex usage:

The following shows how to dynamically load the string and execute it. The result is a table.

[JavaScript]View plaincopy
  1. Local script = "Local EE = {[0] = {id = 0, Lv = 5, text = 'yy'}, [1] = {id = 1, lv = 3, text = 'zz '} return ee"
  2. Local TB = assert (loadstring (SCRIPT ))()
  3. Print (Tb [0]. Text)

The following describes how to dynamically load and execute a string. The result is a method.

[JavaScript]View plaincopy
  1. Local addscript = "function dadd (a, B) return a + B End"
  2. Assert (loadstring (addscript ))()
  3. Print (tostring (dadd (2, 3 )))

Use of loadstring () in Lua

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.