In lua how to use load file variable in main file - lua

my main file syntax is bellow
dofile("subFile.lua")
main('a')
print(subVariable)
my sub file syntax is bellow
local subVariable=""
function main(x)
subVariable="from sub"
end
my subfile contain variable named subVariable want to use this variable in my main file ,why i always get nil.
How to use main file variable in subfile and subfile variable in main file

You're using a local. Remove the " local" and it'll work.
Locals are only accessible by the functions and code behind it.

Related

Cannot import defined variables from Dart file to an another

I have defined the int c in a dart file called (main.dart)
I want to use this variable in another Dart file called (ex.dart). The both dart files are in the same directory (bin)
I used this code (import 'main.dart';) also this (import './main.dart';) . But it gives me this Error: Getter not found: 'c'.
it could not define c , although it was previously defined in (main.dart) file.
any one can help ?

Error in Octave while trying to call function: Undefined near line 1 column 1

When I am trying to call a function it gives me an error. However, I checked my destination path which is correct where my ".m" file is save.
Destination path: C:\Users\Soumaditya\Desktop\ML
File name: warmUpExerciseenter image description here
You are probably mistyping something.
At the matlab or octave terminal, from the directory where you expect your .m file to be, type the command what.
This will show you what is actually there which is relevant to matlab / octave.
Another possibility is that you named your function file one thing, but the name of the function inside the file has named it something else (though, in this case, octave at least would probably have thrown a warning...)
Also make sure that your filename doesn't actually have any weird spaces in the name. A file 'myfunction.m ' is not the same as 'myfunction.m' or ' myfunction.m'
You will need to move all the scripts to the default directory for Octave files on your system, move to your home directory on the Ubuntu system.

Lua - including file doesnt work, how can I fix it?

I have a problem with lua include (dofile, loadfile, require). What I want to do is including file to my main lua file.
Main file - stala_2enb_lua.lua
File to include - zmienne_2enb_modyfikacja
I want to have my main file constant and make changes only in second file, where I want to have variables.
Main file
File to include
I tried all ways like on the screen, but I have no output. It behaves like this all including doesnt matter. There is no error and the variables are not included. How can I make it correctly?
UPDATE
I've managed to load a little bit using dofile, but there is an error which I can't understand. I've found a solution, but i can't understand it properly --> devdocs.io/nginx_lua_module --> ctrf +f = Lua Coroutine Yielding/Resuming
Error after loading function using dofile ("/home/epcsim/WTS_2001_WK05/zmienne_2enb_lua.lua")
Thanks in advance for the help!

File not working in Lua

I am doing a small program for school in Lua, but I need help. I open a file, but when I write, nothing appears in the .txt file. Can anyone help? This is the snippet of code I am trying to fix:
file=io.open('var.txt',"w+")
io.output(file)
io.write('hi!')
Edit: I tried file:close() and io.flush(), but I haven't managed to make it work.
Try the following:
io.output('var.txt')
io.write('hi!')
io.close()
The function io.output allows you to specify a current file for output by its filename. In your example, you were passing a file handler that you created with io.open instead of a filename. This implicitly creates a bad file handler that io.write cannot use.
For more info, check out the chapter on "The Simple I/O Model" from "Programming in Lua".

Using custom Environment Variables in JetBrains products for File watcher Arguments

I am trying to use node-sass as File Watcher in WebStorm.
I created a local variable named STYLE with main stylesheet name inside to add it as variable to File Watcher settings everywhere it needed.
But if I add $STYLE$ in a Path I get an error:
/Users/grawl/Sites/sitename/node_modules/node-sass/bin/node-sass app/styles/$STYLE$.scss public/$STYLE$.css
error reading file "app/styles/$STYLE$.scss"
Process finished with exit code 1
IDE just don't interprets my variable.
Also I tried to use %STYLE% but with no luck.
Please do not blame me for direct mapping filenames in File Watcher without using built-in variables like $FileName$ or $FileNameWithoutExtension$ because even WebStorm 9 EAP does not support preprocessor's dependencies except of built-in preprocessors like Sass and Jade.
This case is not only case to use local variables.
For example I want to put into variables my public/ path (that can be dest/ in other projects) and app/ (can be source/). And so on.
So let's figure out this feature.

Resources