0

Server-side Script

  • updated 9 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 via 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

[LogicNets v7.4.6 on] Scripts can be validated against the LUA code syntax using the code check feature. After completing your script, click on Code Check to receive warning and error messages against LUA version 4 or version 5 or both. Any messages are shown along with 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, mixed. Mixed will check both for Lua4 and Lua5 errors and warnings. You can change the mode of the code validator in the System Configuration settings file.

API Help

Click on 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. This means that the code in the script cannot be executed in lua5, and a crash will occur when trying to. Lua5 is introduced in release 8, so when you are seeing 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. This means that the code in the script cannot be executed in lua4, and a crash will occur when trying to. The Lua4 compiler is used in every release prior to release 8.

  • Lncheck:

These are LogicNets own added code checks that will output warnings and errors if it detects faulty code in the script.
Below is a list with all the warnings and errors:

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
  • 9 mths agoLast active
  • 79Views
  • 4 Following

Home