User Tools

Site Tools


lua_scripting_tips

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
lua_scripting_tips [2025/03/09 09:10]
stanzurek [Complex numbers]
lua_scripting_tips [2025/03/09 10:59] (current)
stanzurek [Rounding in LUA]
Line 105: Line 105:
 ===== Complex numbers ===== ===== Complex numbers =====
 Lua in FEMM handles complex numbers automatically, for example: Lua in FEMM handles complex numbers automatically, for example:
-<code>+<code lua>
 a = 1 + I*2 a = 1 + I*2
 b = 0.3 - I*0.4 b = 0.3 - I*0.4
Line 119: Line 119:
 Full command executed with just the legend parameter set to -1 shows default limits for the legend. This seems to work in pure LUA, and mo_showdensityplot(-1) does not work even in pure LUA: Full command executed with just the legend parameter set to -1 shows default limits for the legend. This seems to work in pure LUA, and mo_showdensityplot(-1) does not work even in pure LUA:
  
-  mo_showdensityplot(legend,gscale,upper_B,lower_B,type) +<code lua> 
-  mo_showdensityplot(-1,0,0,1,"bmag")  +mo_showdensityplot(legend,gscale,upper_B,lower_B,type) 
-  +mo_showdensityplot(-1,0,0,1,"bmag")  
 +</code> 
 + 
 +legend: Set to 0 to hide the plot legend or 1 to show the plot legend. 
 (note that: ''mo_showdensityplot(-1)'' will not work). (note that: ''mo_showdensityplot(-1)'' will not work).
      
-  + 
 +===== Rounding in LUA ===== 
 +Rounding does not appear to be immediately available in LUA 4.0. Teh 
 + 
 +<code lua> 
 +function round_LUA(var_input, round_precision) 
 + 
 +var_floor = floor(var_input/round_precision)*round_precision 
 +var_ceil = ceil(var_input/round_precision)*round_precision 
 +var_rounded = var_floor 
 +  
 +if (var_input > (var_floor + 5*round_precision/10) ) then 
 +var_rounded = var_ceil 
 +end 
 + 
 +return(var_rounded) 
 + 
 +end -- end function 
 + 
 +var_input = 123.44900000003   -- input variable to be rounded 
 +round_precision = 10     -- rounding precision, use: 100, 10, 1, 0.1, 0.01 etc. 
 + 
 +var_output = round_LUA(var_input, round_precision) 
 + 
 +print(var_input) 
 +print(var_output) 
 + 
 +</code>
lua_scripting_tips.1741507805.txt.gz · Last modified: 2025/03/09 09:10 by stanzurek