0

Server-side Script

  • updated 4 mths ago

Description

This part allows you to create server-side scripts in Lua. The LogicNets runtime provides a set of APIs for database access, context manipulation, string manipulation, and other actions. The exact list of APIs and the documentation and examples can be found using the link shown in the part editor.

Use

This part allows you to create server-side scripts in the Lua programming language.

Editor Fields

Field Name Description/Use Type/Options Optional/Mandatory 
Lua Script Allows you to create Lua scripts. Script Mandatory

Code Validator

In LogicNets v7.4.6+, you can have the system validate scripts against the Lua code syntax using the code check feature. After completing your script, click Check Code to receive warning and error messages against Lua version 4 or version 5 or both. The system shows error messages and the Lua-script line number.

Mode

There are 3 modes that you can choose from depending on which LogicNets version you are on: Lua4, Lua5, or Mixed. Mixed checks both for Lua4 and Lua5 errors and warnings. You can change the mode of the code validator in the System Configuration function on the Designer tab.

API Help

Click this link to open an HTML file with Lua code syntax help and examples.

Message

Messages show where the warning or error comes from within the code checker. There are four different message that the code validator can show.

  • Luacheck: This message gets displayed when there are warnings and errors found by the Luacheck code static analyzer tool. See the following link for documentation of the errors and warnings that luacheck can display: https://luacheck.readthedocs.io/en/stable/warnings.html
  • Lua5 compiler: This message means that the Lua5 compiler cannot compile the code in the script, and the system cannot execute the code in the script in Lua5. The system will crash instead. LogicNets introduced Lua5 in v8.0, so if you see these errors in version 7.x your code will still run since it uses the Lua4 compiler.
  • Lua4 compiler: This message means that the Lua4 compiler cannot compile the code in the script, and the system cannot execute the code in the script in Lua4. The system will crash instead. All LogicNets releases prior to v8.0 use the Lua4 compiler.
  • Lncheck: These are LogicNets code checks that will output warnings and errors if it detects faulty code in the script.

Warning Codes and Messages

The following table lists warning codes and associated messages.

Code Message
(W114) Accessing global variable ‘<var>’
(W910) Global ‘<var>' accessed, add to local alias list: 'local <var> = <var>’
(W921) Missing global for ‘<alias>’
(W922) Unrecognized global found ‘<var>’
(W923) Incorrect alias: found ‘<alias>', expected ‘<expected_alias>'
(W924) Incorrect module alias: found ‘<alias>', expected ‘<module_alias>' or ‘<module_alias_short>’W932: Lua4 varargs in
(W932) Lua4 varargs in: <line>
(W933) Possible upvalue in: <line>
(W934) Double dummies in: <line>
(W935) gsub usage in: <line>

Error Codes and Messages

Code  Message
(E911) '<var>' is a LUA-4 global, use alternative as alias: 'local <var> = <lua-5-alternative>’
(E912) '<var>' is a Runtime-4 global, require module: ‘..’ and use ‘..'
(E913) '<var>' is a LUA-4 global, look for an alternativeE925: Lua 5 compiler
(E930) suspected for...in loop in: <line>
(E931) Lua4 getn/strlen calls in: <line>

Save and Validate

When pressing the save button it might say “x warning(s) found. Please start project-validation”. This means that the code validator found an error or warning within your Lua script. To see the error run the code validator by pressing the “check code” button

Configuration Options

It is possible to extend the list of APIs with custom APIs when you have access to the server that is hosting your installation. More information can be found in the topic on Custom Parts.

Example

Please see the example project here.
Reply Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
Like Follow
  • 1 yr agoLast active
  • 89Views
  • 4 Following

Home