this is old code (Lua 5.1)
if (self.wiggleMode == self.LAYER_MODE) then
if (self.wiggleChannel == self.TRANS_MODE) then
LM_TranslateLayer:DrawMe(moho, view)
i have try change to lua 5.3 but error on:
LM_TranslateLayer:DrawMe(moho, view)
error: attempt to index global 'LM_TranslateLayer' (a nil value)
My guess is that LM_TranslateLayer comes from an external library that is loaded via require. Make sure that this library does define global symbols.
In Lua 5.1, require automatically defined a global table to hold the module's content. So, require"foo" definedfoo`.
In Lua 5.2 this changed and the idiom is now local foo = require"foo".
Check how the library that defines LM_TranslateLayer is loaded.
Related
I am using lua to make scripts in my game,
after updating the lua libs version from 5.1 to 5.3, an error appears on the game engine every time I use
math.X in a function
error :
Lua run doFile failed.attempt to index a nil value (global 'math'))
original code :
local value = math.random(1,10)
do you have any solutions ?
when i tried to use if helper in glimmer application.It gives me an error like Uncaught Error: Compile Error: if is not a helper
EDIT: Starting with v0.8.0 there is an inline if.
The version of Glimmerjs you are using does not have an inline if helper, you can either implement it yourself or upgrade your Glimmerjs project to v0.8.0.
To create the helper, run ember g glimmer-helper if, and then edit the file with the following:
// src/ui/components/if/helper.ts
export default function helper([cond, truthy, falsy]) {
return cond ? truthy : falsy;
}
To update, I suggest using ember-cli-update. On top of upgrading your dependencies, you will also have to update your components to the new <Capital> syntax.
When I run a simple piece of code a = torch.Tensor(5,3) in ZeroBraneStudio, I receive the following error:
attempt to index global 'torch' (a nil value)
Does this mean that ZeroBraneStudio does not recognize Torch?
Make sure you select Torch as the interpreter (Project | Lua Interpreter | Torch-7) and configure the path to your th or luajit executable from torch (as described in this post).
I'm using xdg-menu-to-awesome-wm to generate a Lua file containing the GNOME menu, for inclusion in Awesome WM. Since the generator script may not be installed, I need some way for Lua to only require the menu module if it exists.
I don't want to go looking through file names, since it could be anywhere in package.path. One option would be to ignore the exception created when the module does not exist, but I'd rather not ignore any other exceptions - I do want to know if the module contains any syntax or other errors. The reference unfortunately doesn't specify which exceptions can be generated, so I'm not sure how to do it.
If you need to distinguish between a missing module and a syntax error, you can directly access the searcher functions in package.searchers.
These functions will:
Return a loader function if successful
Return a string if the module is not found
Throw an error if there is a syntax error
So what you can do is mimic the way require searches for a module, calling each searcher in turn until one of them returns a function. Unlike require, we need not throw an error if the module is not found, i.e. if every searcher function returns a string.
function isModuleAvailable(name)
if package.loaded[name] then
return true
else
for _, searcher in ipairs(package.searchers or package.loaders) do
local loader = searcher(name)
if type(loader) == 'function' then
package.preload[name] = loader
return true
end
end
return false
end
end
Look, I had the same problem with 'luafilesystem' module, I worked it out like this,
local haslfs,lfs = pcall(require,"lfs")
if haslfs then
configLines["PROJECT_HOME"] = lfs.currentdir()
else
configLines["PROJECT_HOME"] = prompt("Project path > ")
end
'lfs' here is the module handle . And pcall is used to know if the module is really loaded without propagating the error.
What I do is wrap the require in a pcall so that the module is loaded and a fail to load can be caught. There is a fully worked function which I use to download and install the missing modules from our servers here:
http://www.fhug.org.uk/wiki/doku.php?id=plugins:code_snippets:module_require_with_load
function loadrequire(module)
local function requiref(module)
require(module)
end
res = pcall(requiref,module)
if not(res) then
-- Do Stuff when no module
end
end
loadrequire('menu')
If I compile the following module into a dll
namespace MyNs
module SomeModule =
do printfn "module loading"
let x = 23
then reference the dll in FSI and execute the command open MyNs.SomeModule "module loading" does not print immediately. It only prints when I access x which causes all the top level let and do bindings to execute (normal behavior I know in the .NET world). Is there any way, perhaps via an attribute on the module, I can indicate that module should load immediately upon opening in FSI?
Opening a module never does anything at runtime. It just puts all the symbols in the opened namespace in scope for unqualified access below the open statement.
Section 12.5 of the language spec is what you want to read - this details when the static initialization of a module will run.
Given that, the only time when this initialization is run automatically, as far as I know, is for last module in an exe.
I.e. I don't think there is a direct way to accomplish what you want.
If you have reflective access to the module:
ModuleType.TypeInitializer.Invoke(null, null)
will invoke the static initialization.
You can add the AutoOpen attribute to the module
[<AutoOpen>]
module SomeModule =
do printfn "module loading"
let x = 23
However this will only print the module loading message when you reference x.
Not sure if you found the solution to your problem but in my case I wanted to start an agent when my website was starting and it was indeed starting twice like you mentioned.
What I did was set a method let start() = inside the module and invoke the method using a static do xxx.start() from my main Site type.
Found that by reading the language spec Kurt linked.